Skip to main content

BufferProvider

Trait BufferProvider 

Source
pub trait BufferProvider<'a> {
    type Buffer: AsMut<[u8]> + Into<Bytes<'a>>;
    type ProvisionError: Debug;

    // Required method
    fn provide_buffer(
        &mut self,
        len: usize,
    ) -> Result<Self::Buffer, Self::ProvisionError>;
}
Expand description

A trait to describe anything that can allocate memory.

Returned memory can be borrowed or owned. Either way, it is bound by the 'a lifetime - usually just the lifetime of the underlying buffer.

The client does not store any references to memory returned by this provider.

Required Associated Types§

Source

type Buffer: AsMut<[u8]> + Into<Bytes<'a>>

The type returned from a successful buffer provision. Must implement AsMut so that it can be borrowed mutably right after allocation for initialization and Into for storing as Bytes.

Source

type ProvisionError: Debug

The error type returned from a failed buffer provision.

Required Methods§

Source

fn provide_buffer( &mut self, len: usize, ) -> Result<Self::Buffer, Self::ProvisionError>

If successful, returns contiguous memory with a size in bytes of the len argument.

§Errors

Returns a value of its associated error type if the buffer provision fails.

Implementors§