pub trait FixedCodec {
type Value<'wire>
where Self: 'wire;
type EncodeError: Debug;
type Plan<'value>: EncodePlan
where Self: 'value;
const WIDTH: usize;
// Required methods
fn decode<'wire>(bytes: &'wire [u8]) -> Self::Value<'wire>;
fn plan<'value>(
value: Self::Value<'value>,
) -> Result<Self::Plan<'value>, Self::EncodeError>;
}Expand description
A codec whose encoded representation always has one fixed width.
Self::WIDTH must be nonzero. Every successful Self::plan must report that
exact encoded length. For every such plan, EncodePlan::write_into called with
an output slice of exactly Self::WIDTH bytes must write a complete representation
whose decoding recovers the same semantic value supplied to Self::plan. Decoding
is total for every exact-width byte pattern. A codec that violates these requirements
is contract-invalid.
When a layout builder derives a byte-range source through
Self::Value<'static>: TryFrom<usize>, the complete conversion and codec round trip
must preserve that source value: converting the decoded planned representation back to
usize must produce the original relative length or absolute endpoint.
Self::plan completes all fallible encoding work before a caller mutates an output
buffer. Layout parsing establishes exact-width bounds before calling Self::decode.
Required Associated Constants§
Required Associated Types§
Sourcetype Value<'wire>
where
Self: 'wire
type Value<'wire> where Self: 'wire
Semantic value represented by an exact-width wire representation.
Sourcetype EncodeError: Debug
type EncodeError: Debug
Error returned while preparing an encoded value.
Sourcetype Plan<'value>: EncodePlan
where
Self: 'value
type Plan<'value>: EncodePlan where Self: 'value
Prepared fixed-width encoded bytes.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".