Skip to main content

Sink

Trait Sink 

pub trait Sink {
    type Error: Error;

    // Required methods
    fn put(&mut self, bytes: &[u8]) -> Result<(), Self::Error>;
    fn reserve(&mut self, additional: usize) -> Result<(), Self::Error>;
}
Expand description

Destination for encoded bytes.

The error type says how writing can fail. A fixed slice runs out of space, a Vec can fail to allocate, and a Counter never fails.

Required Associated Types§

type Error: Error

Error returned when the sink cannot take more bytes.

Required Methods§

fn put(&mut self, bytes: &[u8]) -> Result<(), Self::Error>

Appends bytes.

§Errors

Returns Error if the sink cannot take all of bytes. The sink is then unchanged.

fn reserve(&mut self, additional: usize) -> Result<(), Self::Error>

Makes room for additional more bytes, so that putting them does not fail or reallocate.

§Errors

Returns Error if the sink cannot make the room.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

§

impl Sink for Vec<u8>

Available on crate feature alloc only.
§

type Error = TryReserveError

§

fn put(&mut self, bytes: &[u8]) -> Result<(), TryReserveError>

§

fn reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

§

impl<T: Sink + ?Sized> Sink for &mut T

§

type Error = <T as Sink>::Error

§

fn put(&mut self, bytes: &[u8]) -> Result<(), T::Error>

§

fn reserve(&mut self, additional: usize) -> Result<(), T::Error>

Implementors§

§

impl Sink for Counter

§

type Error = !

§

impl Sink for GrowBuffer

Available on crate feature alloc only.
§

impl Sink for SliceSink<'_>

§

impl<const N: usize> Sink for ArrayBuffer<N>