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>
impl<'d, 's> BufferRef<'d, 's>
Sourcepub fn new(
buffer: &'d mut [u8],
initialized: &'s mut usize,
) -> BufferRef<'d, 's>
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.
Sourcepub unsafe fn advance(&mut self, num_bytes: usize)
pub unsafe fn advance(&mut self, num_bytes: usize)
Advances the split of initialized/uninitialized data by num_bytes
to
the right.
Sourcepub fn extend<I>(&mut self, bytes: I) -> Result<(), CapacityError>
pub fn extend<I>(&mut self, bytes: I) -> Result<(), CapacityError>
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.
Sourcepub fn write(&mut self, bytes: &[u8]) -> Result<(), CapacityError>
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.
Sourcepub unsafe fn uninitialized_mut(&mut self) -> &mut [u8] ⓘ
pub unsafe fn uninitialized_mut(&mut self) -> &mut [u8] ⓘ
Returns the uninitialized part of the buffer.
Sourcepub fn initialized(self) -> &'d [u8] ⓘ
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.
Trait Implementations§
Source§impl<'r, 'd, 's> Buffer<'d> for &'r mut BufferRef<'d, 's>
impl<'r, 'd, 's> Buffer<'d> for &'r mut BufferRef<'d, 's>
Source§type Intermediate = BufferRefBuffer<'r, 'd, 's>
type Intermediate = BufferRefBuffer<'r, 'd, 's>
T: Buffer
into a BufferRef
.Source§fn to_to_buffer_ref(self) -> Self::Intermediate
fn to_to_buffer_ref(self) -> Self::Intermediate
T: Buffer
into the intermediate step to BufferRef
.