pub trait FrameRead<'a>: Sized {
type Error: Debug;
// Required method
fn decode(buf: &mut &'a [u8]) -> Result<Self, Self::Error>;
}Expand description
Decodes Self from a zero-copy buffer cursor.
The cursor buf is a &mut &'a [u8] - a mutable reference to a shared
slice. Each call to decode advances the cursor by consuming bytes from
the front. The lifetime 'a ties any borrowed data in Self back to
the original buffer, ensuring zero allocation for slice fields.
§Implementing for custom types
Most types should use #[derive(FrameRead)] from ace-macros.
Manual implementation is required when field lengths depend on context
from a parent struct - use [FrameReadWithContext] in those cases.
§Blanket impls provided
u8,u16,u32- big-endian[u8; N]- fixed-size arrays&'a [u8]- consumes all remaining bytesOption<T: FrameRead>-Noneif buffer empty,Some(T::decode(...))otherwiseFrameIter<'a, T: FrameRead>- lazy iterator consuming all remaining bytes
Required Associated Types§
Required 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.
Implementations on Foreign Types§
Source§impl<'a> FrameRead<'a> for &'a [u8]
Consumes all remaining bytes - only valid as a trailing field.
impl<'a> FrameRead<'a> for &'a [u8]
Consumes all remaining bytes - only valid as a trailing field.
Source§impl<'a, T> FrameRead<'a> for Option<T>where
T: FrameRead<'a>,
None if buffer is empty, Some(T::decode(...)) otherwise.
impl<'a, T> FrameRead<'a> for Option<T>where
T: FrameRead<'a>,
None if buffer is empty, Some(T::decode(...)) otherwise.