Trait IsHeader

Source
pub trait IsHeader {
    type Error: Debug + Display;

    // Required methods
    fn new(msg_len: u64) -> Self
       where Self: Sized;
    fn size(&self) -> u64;
    fn as_bytes(&self) -> Bytes;
    fn as_bytes_mut(&self) -> BytesMut;
    fn from_bytes(bytes: Bytes) -> Result<Self, Self::Error>
       where Self: Sized;
    fn header_size() -> usize;

    // Provided method
    fn blank() -> Self
       where Self: Sized { ... }
}
Expand description

Trait for methods that should be found on header implementations

Required Associated Types§

Required Methods§

Source

fn new(msg_len: u64) -> Self
where Self: Sized,

Create a new header

Source

fn size(&self) -> u64

Get the size of the message contained within

Source

fn as_bytes(&self) -> Bytes

Get the header, represented as bytes

Source

fn as_bytes_mut(&self) -> BytesMut

Get the header, represented as bytes

Source

fn from_bytes(bytes: Bytes) -> Result<Self, Self::Error>
where Self: Sized,

Create a new header, from some bytes. This should do all necessary validation checks.

§Errors

if the header contained in bytes was invalid

Source

fn header_size() -> usize

size of the header. this should never change and is used to read the appropreate number of bytes when deserializing

Provided Methods§

Source

fn blank() -> Self
where Self: Sized,

Create a new header with a message size of zero

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§