pub struct WriteBuffer<'a> { /* private fields */ }Expand description
Write buffer for compression-codecs.
Currently it only supports initialized buffer, but will support uninitialized buffer soon.
§Layout
| buffer |
| written and initialized | unwritten but initialized | unwritten and uninitializedImplementations§
Source§impl<'a> WriteBuffer<'a>
impl<'a> WriteBuffer<'a>
pub fn new_initialized(buffer: &'a mut [u8]) -> Self
pub fn new_uninitialized(buffer: &'a mut [MaybeUninit<u8>]) -> Self
pub fn capacity(&self) -> usize
pub fn as_mut_ptr(&mut self) -> *mut u8
pub fn initialized_len(&self) -> usize
pub fn written(&self) -> &[u8] ⓘ
Sourcepub fn written_len(&self) -> usize
pub fn written_len(&self) -> usize
Convenient method for .writen().len()
Sourcepub fn has_no_spare_space(&self) -> bool
pub fn has_no_spare_space(&self) -> bool
Buffer has no spare space to write any data
Sourcepub fn initialize_unwritten(&mut self) -> &mut [u8] ⓘ
pub fn initialize_unwritten(&mut self) -> &mut [u8] ⓘ
Initialize all uninitialized, unwritten part to initialized, unwritten part Return all unwritten part
Sourcepub fn advance(&mut self, amount: usize)
pub fn advance(&mut self, amount: usize)
Advance written index within initialized part.
Note that try to advance into uninitialized part would panic.
pub fn reset(&mut self)
Sourcepub unsafe fn unwritten_mut(&mut self) -> &mut [MaybeUninit<u8>]
pub unsafe fn unwritten_mut(&mut self) -> &mut [MaybeUninit<u8>]
Returns a mutable reference to the unwritten part of the buffer without ensuring that it has been fully initialized.
§Safety
The caller must not de-initialize portions of the buffer that have already been initialized.
This includes any bytes in the region returned by this function.
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.
WriteBuffer assumes that bytes are never de-initialized, so this method
does nothing when called with fewer bytes than are already known to be initialized.
§Safety
The caller must ensure that n unfilled bytes of the buffer have already been initialized.
Sourcepub unsafe fn assume_init_and_advance(&mut self, n: usize)
pub unsafe fn assume_init_and_advance(&mut self, n: usize)
Convenient function combining WriteBuffer::assume_init and WriteBuffer::advance.
§Safety
The caller must ensure that n unfilled bytes of the buffer have already been initialized.
Sourcepub unsafe fn set_written_and_initialized_len(&mut self, n: usize)
pub unsafe fn set_written_and_initialized_len(&mut self, n: usize)
Convenient function combining WriteBuffer::assume_init and WriteBuffer::advance,
works similar to Vec::set_len.
§Safety
The caller must ensure that first n bytes of the buffer have already been initialized.