packet::serialize

Trait BufferAlloc

Source
pub trait BufferAlloc<Output> {
    type Error;

    // Required method
    fn alloc(self, len: usize) -> Result<Output, Self::Error>;
}
Expand description

An object capable of allocating new buffers.

A BufferAlloc<Output> is an object which is capable of allocating new buffers of type Output.

Two blanket implementations of BufferProvider are given for any type which implements BufferAlloc<O>. One blanket implementation works for any input buffer type, I, and produces buffers of type Either<I, O> as output. One blanket implementation works only when the input and output buffer types are the same, and produces buffers of that type. See the documentation on those impls for more details.

The following implementations of BufferAlloc are provided:

  • Any FnOnce(usize) -> Result<O, E> implements BufferAlloc<O, Error = E>
  • () implements BufferAlloc<Never, Error = ()> (an allocator which always fails)
  • new_buf_vec implements BufferAlloc<Buf<Vec<u8>>, Error = Never> (an allocator which infallibly heap-allocates Vecs)

Required Associated Types§

Source

type Error

The type of errors returned from alloc.

Required Methods§

Source

fn alloc(self, len: usize) -> Result<Output, Self::Error>

Attempts to allocate a new buffer of size len.

Implementations on Foreign Types§

Source§

impl BufferAlloc<Infallible> for ()

Source§

type Error = ()

Source§

fn alloc(self, _len: usize) -> Result<Never, ()>

Implementors§

Source§

impl<O, E, F: FnOnce(usize) -> Result<O, E>> BufferAlloc<O> for F

Source§

type Error = E