Struct OutBuffer

pub struct OutBuffer<'a, C: WriteBuf + ?Sized> { /* private fields */ }

Wrapper around an output buffer.

C is usually either [u8] or Vec<u8>.

Bytes will be written starting at dst[pos].

pos will be updated after writing.

Invariant

pos <= dst.capacity()

Implementations

impl<'a, C: WriteBuf + ?Sized> OutBuffer<'a, C>

fn around(dst: &'a mut C) -> Self

Returns a new OutBuffer around the given slice.

Starts with pos = 0.

fn around_pos(dst: &'a mut C, pos: usize) -> Self

Returns a new OutBuffer around the given slice, starting at the given position.

If pos is past the initialized part of dst (for example a Vec whose len() is smaller than pos), the gap is zero-filled, as a Cursor would do.

Panics

If pos > dst.capacity().

fn pos(&self) -> usize

Returns the current cursor position.

Guaranteed to be <= self.capacity()

fn capacity(&self) -> usize

Returns the capacity of the underlying buffer.

unsafe fn set_pos(&mut self, pos: usize)

Sets the new cursor position.

Panics

If pos > self.dst.capacity().

Safety

Data up to pos must have actually been written to.

fn as_slice<'b>(&'b self) -> &'a [u8]
where
    'b: 'a,

Returns the part of this buffer that was written to.

fn as_mut_ptr(&mut self) -> *mut u8

Returns a pointer to the start of this buffer.

Trait Implementations

impl<'a, C: Debug + WriteBuf + ?Sized> Debug for OutBuffer<'a, C>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Auto Trait Implementations

impl<'a, C> !UnwindSafe for OutBuffer<'a, C>

impl<'a, C> Freeze for OutBuffer<'a, C> where &'a mut C: Freeze, C: ?Sized,

impl<'a, C> RefUnwindSafe for OutBuffer<'a, C> where &'a mut C: RefUnwindSafe, C: ?Sized,

impl<'a, C> Send for OutBuffer<'a, C> where &'a mut C: Send, C: ?Sized,

impl<'a, C> Sync for OutBuffer<'a, C> where &'a mut C: Sync, C: ?Sized,

impl<'a, C> Unpin for OutBuffer<'a, C> where &'a mut C: Unpin, C: ?Sized,

impl<'a, C> UnsafeUnpin for OutBuffer<'a, C> where &'a mut C: UnsafeUnpin, C: ?Sized,

Blanket Implementations

impl<T> Any for OutBuffer<'a, C> where T: 'static + ?Sized,

impl<T> Borrow<T> for OutBuffer<'a, C> where T: ?Sized,

impl<T> BorrowMut<T> for OutBuffer<'a, C> where T: ?Sized,

impl<T> From<T> for OutBuffer<'a, C>

impl<T, U> Into<U> for OutBuffer<'a, C> where U: From<T>,

impl<T, U> TryFrom<U> for OutBuffer<'a, C> where U: Into<T>,

impl<T, U> TryInto<U> for OutBuffer<'a, C> where U: TryFrom<T>,