pub struct SnapBuf { /* private fields */ }Expand description
A copy on write buffer.
See the crate level documentation for more details.
Implementations§
Source§impl SnapBuf
impl SnapBuf
Sourcepub fn resize(&mut self, new_len: usize, value: u8)
pub fn resize(&mut self, new_len: usize, value: u8)
Resizes the buffer, to the given length.
If new_len is greater than len, the new space in the buffer is filled with copies of value.
This is more efficient if value == 0.
Sourcepub fn truncate(&mut self, new_len: usize)
pub fn truncate(&mut self, new_len: usize)
Shortens the buffer, keeping the first new_len bytes and discarding the rest.
If new_len is greater or equal to the buffer’s current length, this has no effect.
Sourcepub fn fill_range(&mut self, range: Range<usize>, value: u8)
pub fn fill_range(&mut self, range: Range<usize>, value: u8)
Fill the given range with copies of value.
This is equivalent to calling write with a slice filled with value.
Calling this with value = 0 is not guaranteed to free up the zeroed segments,
use clear_range if that is required.
pub fn read(&self, offset: usize) -> &[u8] ⓘ
Sourcepub fn write(&mut self, offset: usize, data: &[u8])
pub fn write(&mut self, offset: usize, data: &[u8])
Writes data at the specified offset.
If this extends past the current end of the buffer, the buffer is automatically resized. If offset is larger than the current buffer length, the space between the current buffer end and the written region is filled with zeros.
Zeroing parts of the buffer using this method is not guaranteed to free up the zeroed segments, use write_with_zeros if that is required.
Sourcepub fn write_with_zeros(&mut self, offset: usize, data: &[u8])
pub fn write_with_zeros(&mut self, offset: usize, data: &[u8])
Like write, but detects and frees newly zeroed segments in the buffer.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the buffer, the number of bytes it contains.
The memory footprint of the buffer may be much smaller than this due to omission of zero segments and sharing with other buffers.
Sourcepub fn clear_range(&mut self, range: Range<usize>)
pub fn clear_range(&mut self, range: Range<usize>)
Fill a range with zeros, freeing memory if possible.
§Panics
Panics if range end is range.end > self.len().
Sourcepub fn chunks(&self) -> impl Iterator<Item = &[u8]>
pub fn chunks(&self) -> impl Iterator<Item = &[u8]>
Returns an iterator over the byte slices constituting the buffer.
The returned slices may overlap.
pub fn extend_from_slice(&mut self, data: &[u8])
Trait Implementations§
Source§impl Extend<u8> for SnapBuf
impl Extend<u8> for SnapBuf
Source§fn extend<T: IntoIterator<Item = u8>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = u8>>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)