pub trait Container {
    // Required methods
    fn reserve(&mut self, n: usize);
    fn len(&self) -> usize;
    fn capacity(&self) -> usize;
    unsafe fn spare_mut(&mut self) -> &mut [MaybeUninit<u8>];
    unsafe fn advance(&mut self, n: usize);

    // Provided method
    fn is_empty(&self) -> bool { ... }
}

Required Methods§

source

fn reserve(&mut self, n: usize)

Reserve at least n bytes that can be used in Container::spare_mut.

source

fn len(&self) -> usize

Number of initialized bytes.

source

fn capacity(&self) -> usize

Return the capacity reserved.

source

unsafe fn spare_mut(&mut self) -> &mut [MaybeUninit<u8>]

The returned uninit slice must not be empty.

NOTE that the returned uninit slice might be smaller than bytes reserved in Container::reserve or (Container::capacity - Container::len).

This is because that the container might be a ring buffer. If you consume all uninit slices, then the sum of their lengths must be equal to the spare capacity (Container::capacity - Container::len).

Safety

The slice returned must not be read from and users should never write uninitialized bytes to it.

source

unsafe fn advance(&mut self, n: usize)

Safety

The users must have actually initialized at least n bytes in the uninit slice returned by Container::spare_mut.

Provided Methods§

source

fn is_empty(&self) -> bool

If there is no initialized bytes in the container, return true.

Implementations on Foreign Types§

source§

impl Container for BytesMut

Available on crate feature bytes only.
source§

fn reserve(&mut self, n: usize)

source§

fn len(&self) -> usize

source§

fn capacity(&self) -> usize

source§

unsafe fn spare_mut(&mut self) -> &mut [MaybeUninit<u8>]

source§

unsafe fn advance(&mut self, n: usize)

source§

impl<T: Container> Container for &mut T

source§

fn reserve(&mut self, n: usize)

source§

fn len(&self) -> usize

source§

fn capacity(&self) -> usize

source§

unsafe fn spare_mut(&mut self) -> &mut [MaybeUninit<u8>]

source§

unsafe fn advance(&mut self, n: usize)

source§

impl Container for Vec<u8>

source§

fn reserve(&mut self, n: usize)

source§

fn len(&self) -> usize

source§

fn capacity(&self) -> usize

source§

unsafe fn spare_mut(&mut self) -> &mut [MaybeUninit<u8>]

source§

unsafe fn advance(&mut self, n: usize)

Implementors§