Struct SnapBuf

Source
pub struct SnapBuf { /* private fields */ }

Implementations§

Source§

impl SnapBuf

Source

pub fn new() -> Self

Creates an empty buffer.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn write_with_zeros(&mut self, offset: usize, data: &[u8])

Like write, but detects and frees newly zeroed segments in the buffer.

Source

pub fn is_empty(&self) -> bool

Returns true if the buffer length is zero.

Source

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.

Source

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().

Source

pub fn clear(&mut self)

Clears all data and sets length to 0.

Source

pub fn chunks(&self) -> impl Iterator<Item = &[u8]>

Returns an iterator over the byte slices constituting the buffer.

The returned slices may overlap.

Source

pub fn iter(&self) -> impl Iterator<Item = &u8>

Returns an iterator over the buffer.

Source

pub fn extend_from_slice(&mut self, data: &[u8])

Trait Implementations§

Source§

impl Debug for SnapBuf

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SnapBuf

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Extend<u8> for SnapBuf

Source§

fn extend<T: IntoIterator<Item = u8>>(&mut self, iter: T)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl FromIterator<u8> for SnapBuf

Source§

fn from_iter<T: IntoIterator<Item = u8>>(iter: T) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

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.