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§
Sourcefn as_bytes_mut(&self) -> BytesMut
fn as_bytes_mut(&self) -> BytesMut
Get the header, represented as bytes
Sourcefn from_bytes(bytes: Bytes) -> Result<Self, Self::Error>where
Self: Sized,
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
Sourcefn header_size() -> usize
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§
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.