tokio_io_utility

Trait Container

Source
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 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)

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)

Implementors§