Skip to main content

BufFactory

Trait BufFactory 

Source
pub trait BufFactory:
    Clone
    + Default
    + Debug {
    type Buf: Clone + Debug + AsRef<[u8]>;
    type DgramBuf: AsRef<[u8]> + From<Vec<u8>>;

    // Required methods
    fn buf_from_slice(buf: &[u8]) -> Self::Buf;
    fn dgram_buf_from_slice(buf: &[u8]) -> Self::DgramBuf;
}
Expand description

A trait for providing internal storage buffers for streams, enabling zero-copy operations. The associated type Buf can be any type that dereferences to a slice, but should be fast to clone, eg. by wrapping it with an Arc.

Required Associated Types§

Source

type Buf: Clone + Debug + AsRef<[u8]>

The type of the generated buffer. The clone operation should be cheap, e.g., by using an Arc.

Source

type DgramBuf: AsRef<[u8]> + From<Vec<u8>>

The type of generated buffers used for datagrams. These do not need to be cloneable.

Required Methods§

Source

fn buf_from_slice(buf: &[u8]) -> Self::Buf

Generate a new buffer from a given slice, the buffer must contain the same data as the original slice.

Source

fn dgram_buf_from_slice(buf: &[u8]) -> Self::DgramBuf

Generate a new datagram buffer from a given slice, the buffer must contain the same data as the original slice.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§