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.

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,

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

fn borrow_mut(&mut self) -> &mut T

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

fn from(t: T) -> T

Returns the argument unchanged.

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

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

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

type Error = never;
fn try_from(value: U) -> Result<T, never>

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

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>