Struct BufferRef

Source
pub struct BufferRef<'data, 'size> { /* private fields */ }
Expand description

A reference to an uninitialized or partially initialized byte buffer.

It keeps track of how many bytes (from the start of the buffer) are initialized.

Implementations§

Source§

impl<'d, 's> BufferRef<'d, 's>

Source

pub fn new( buffer: &'d mut [u8], initialized: &'s mut usize, ) -> BufferRef<'d, 's>

Creates a buffer reference from the buffer and a pointer where the length should be written to.

Important: initialized must initially be zero.

Source

pub unsafe fn advance(&mut self, num_bytes: usize)

Advances the split of initialized/uninitialized data by num_bytes to the right.

Source

pub fn extend<I>(&mut self, bytes: I) -> Result<(), CapacityError>
where I: Iterator<Item = u8>,

Writes the bytes yielded by the bytes iterator into the buffer.

If the iterator yields more bytes than the buffer can contain, a CapacityError is returned.

Source

pub fn write(&mut self, bytes: &[u8]) -> Result<(), CapacityError>

Writes the byte slice into the buffer.

If the slice contains more bytes than the buffer can contain, a CapacityError is returned.

Source

pub unsafe fn uninitialized_mut(&mut self) -> &mut [u8]

Returns the uninitialized part of the buffer.

Source

pub fn initialized(self) -> &'d [u8]

Consumes the (mutable) buffer reference to produce a slice of the initialized data that is independent from the BufferRef instance.

Source

pub fn remaining(&self) -> usize

Returns the amount of uninitialized bytes that are left.

Trait Implementations§

Source§

impl<'r, 'd, 's> Buffer<'d> for &'r mut BufferRef<'d, 's>

Source§

type Intermediate = BufferRefBuffer<'r, 'd, 's>

Intermediate result of converting the T: Buffer into a BufferRef.
Source§

fn to_to_buffer_ref(self) -> Self::Intermediate

Converts the T: Buffer into the intermediate step to BufferRef.
Source§

fn cap_at(self, len: usize) -> CapAt<'data, Self>
where Self: Sized,

Caps the buffer at the specified byte index. Read more

Auto Trait Implementations§

§

impl<'data, 'size> Freeze for BufferRef<'data, 'size>

§

impl<'data, 'size> RefUnwindSafe for BufferRef<'data, 'size>

§

impl<'data, 'size> Send for BufferRef<'data, 'size>

§

impl<'data, 'size> Sync for BufferRef<'data, 'size>

§

impl<'data, 'size> Unpin for BufferRef<'data, 'size>

§

impl<'data, 'size> !UnwindSafe for BufferRef<'data, 'size>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.