Skip to main content

Buf

Trait Buf 

Source
pub trait Buf<T>:
    Default
    + Debug
    + Deref<Target = [T]>
    + DerefMut
    + Send
    + Sync
    + 'static
    + Sealed {
    // Required methods
    fn zeroed(len: usize) -> Self;
    fn zeroed_arr2(len: usize) -> impl Buf<[T; 2]>;
    fn capacity(&self) -> usize;
    fn set_len(&mut self, new_len: usize);
    fn grow_zeroed(&mut self, new_size: usize);
}

Required Methods§

Source

fn zeroed(len: usize) -> Self

Create a new Buf of length len with all elements set to zero.

Implementations of this directly allocate zeroed memory and do not write zeroes to the elements explicitly.

Source

fn zeroed_arr2(len: usize) -> impl Buf<[T; 2]>

Create a new Buf of the same kind but for two-element arrays of `T``.

This method is useful in methods generic over Buf which need a temporary buffer over arrays of size two of T, that is the same kind of buffer the method is called with. That is, a fn foo(b: impl Buf<T>) called with a HugePageMemory can use this method to create a HugePageMemory<[T;2]>.

Source

fn capacity(&self) -> usize

Capacity of the Buf.

Source

fn set_len(&mut self, new_len: usize)

Sets the length of the buffer

§Panic

Panics if len > self.capacity.

Source

fn grow_zeroed(&mut self, new_size: usize)

Grow the Buf to new_size and fill with zeroes.

let mut v: Vec<u8> = Vec::zeroed(20);
assert_eq!(20, v.len());
v.grow_zeroed(40);
assert_eq!(40, v.len());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: Zeroable + Clone + Default + Debug + Send + Sync + 'static> Buf<T> for Vec<T>

Source§

fn zeroed(len: usize) -> Self

Source§

fn zeroed_arr2(len: usize) -> impl Buf<[T; 2]>

Source§

fn capacity(&self) -> usize

Source§

fn set_len(&mut self, new_len: usize)

Source§

fn grow_zeroed(&mut self, new_size: usize)

Implementors§

Source§

impl<T: Zeroable + Clone + Default + Debug + Send + Sync + 'static> Buf<T> for HugePageMemory<T>