pub struct ReadBuf<'a> { /* private fields */ }Expand description
A wrapper around a byte buffer that is incrementally filled and initialized.
Implementations§
Source§impl<'a> ReadBuf<'a>
impl<'a> ReadBuf<'a>
Sourcepub fn uninit(data: &'a mut [MaybeUninit<u8>]) -> ReadBuf<'a>
pub fn uninit(data: &'a mut [MaybeUninit<u8>]) -> ReadBuf<'a>
Create a new ReadBuf from a fully uninitialized buffer.
Use assume_init if part of the buffer is known to be already
initialized.
Sourcepub fn as_mut(&mut self) -> ReadBufMut<'_>
pub fn as_mut(&mut self) -> ReadBufMut<'_>
Get a mutable reference to this buffer as a ReadBufMut.
Sourcepub fn into_all(self) -> &'a mut [MaybeUninit<u8>]
pub fn into_all(self) -> &'a mut [MaybeUninit<u8>]
Consume the buffer, returning the entire partially initialized backing slice.
Sourcepub fn into_parts(
self,
) -> (&'a mut [u8], &'a mut [u8], &'a mut [MaybeUninit<u8>])
pub fn into_parts( self, ) -> (&'a mut [u8], &'a mut [u8], &'a mut [MaybeUninit<u8>])
Consume the buffer, returning its three parts, the filled portion, the unfilled portion and the uninitialized portion.
Sourcepub fn into_filled(self) -> &'a mut [u8] ⓘ
pub fn into_filled(self) -> &'a mut [u8] ⓘ
Consume the buffer, returning its filled portion.
Source§impl ReadBuf<'_>
These methods are also present on ReadBufMut.
impl ReadBuf<'_>
These methods are also present on ReadBufMut.
Sourcepub fn filled_mut(&mut self) -> &mut [u8] ⓘ
pub fn filled_mut(&mut self) -> &mut [u8] ⓘ
Get a mutable reference to the filled portion of the buffer.
Sourcepub fn initialized(&self) -> &[u8] ⓘ
pub fn initialized(&self) -> &[u8] ⓘ
Get a shared reference to the initialized portion of the buffer.
This includes the filled portion.
Sourcepub fn initialized_mut(&mut self) -> &mut [u8] ⓘ
pub fn initialized_mut(&mut self) -> &mut [u8] ⓘ
Get a mutable reference to the initialized portion of the buffer.
This includes the filled portion.
Sourcepub unsafe fn unfilled_mut(&mut self) -> &mut [MaybeUninit<u8>]
pub unsafe fn unfilled_mut(&mut self) -> &mut [MaybeUninit<u8>]
Get a mutable reference to the unfilled part of the buffer without ensuring that it has been fully initialized.
§Safety
The caller must not deinitialize portions of the buffer that have already been initialized.
Sourcepub fn all(&self) -> &[MaybeUninit<u8>]
pub fn all(&self) -> &[MaybeUninit<u8>]
Get a shared reference to the entire backing buffer.
Sourcepub unsafe fn all_mut(&mut self) -> &mut [MaybeUninit<u8>]
pub unsafe fn all_mut(&mut self) -> &mut [MaybeUninit<u8>]
Get a mutable reference to the entire backing buffer.
§Safety
The caller must not deinitialize portions of the buffer that have already been initialized.
Sourcepub fn initialize_unfilled(&mut self) -> &mut [u8] ⓘ
pub fn initialize_unfilled(&mut self) -> &mut [u8] ⓘ
Get a mutable reference to the unfilled part of the buffer, ensuring it is fully
initialized.
Since ReadBuf tracks the region of the buffer that has been initialized, this is
effectively “free” after the first use.
Sourcepub fn initialize_unfilled_to(&mut self, n: usize) -> &mut [u8] ⓘ
pub fn initialize_unfilled_to(&mut self, n: usize) -> &mut [u8] ⓘ
Get a mutable reference to the first n bytes of the unfilled part of the buffer, ensuring
it is fully initialized.
§Panics
Panics if self.remaining() is less than n.
Sourcepub fn remaining(&self) -> usize
pub fn remaining(&self) -> usize
Get the number of bytes at the end of the slice that have not yet been filled.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clear the buffer, resetting the filled region to empty.
The number of initialized bytes is not changed, and the contents of the buffer is not modified.
Sourcepub fn add_filled(&mut self, n: usize)
pub fn add_filled(&mut self, n: usize)
Increase the size of the filled region of the buffer by n bytes.
The number of initialized bytes is not changed.
§Panics
Panics if the filled region of the buffer would become larger than the initialized region.
Sourcepub fn set_filled(&mut self, n: usize)
pub fn set_filled(&mut self, n: usize)
Set the size of the filled region of the buffer to n.
The number of initialized bytes is not changed.
Note that this can be used to shrink the filled region of the buffer in addition to
growing it (for example, by a Read implementation that compresses data in-place).
§Panics
Panics if the filled region of the buffer would become larger than the initialized region.
Sourcepub unsafe fn assume_init(&mut self, n: usize)
pub unsafe fn assume_init(&mut self, n: usize)
Asserts that the first n unfilled bytes of the buffer are initialized.
ReadBuf assumes that bytes are never deinitialized, so this method does nothing when
called with fewer bytes than are already known to be initialized.
§Safety
The caller must ensure that the first n unfilled bytes of the buffer have already been
initialized.