Skip to main content

RangeSource

Trait RangeSource 

Source
pub trait RangeSource<C: FixedCodec> {
    type Error: Debug;

    // Required methods
    fn to_bytes(value: C::Value<'_>) -> Result<usize, Self::Error>;
    fn from_bytes(bytes: usize) -> Result<C::Value<'static>, Self::Error>;
}
Expand description

Performs checked bidirectional structural conversion between a decoded fixed source representation and byte geometry.

A range uses the geometry as either a relative byte length (bytes(source)) or an exclusive endpoint relative to representation byte zero (bytes_to(source)). Generated parsers call Self::to_bytes at the consuming range before their existing checked range and input-bounds logic. During crate::PreparedLayout preparation, generated builders derive required geometry, require shared sources to agree on that geometry, and call Self::from_bytes once for each source before planning its physical codec. Commit only writes the prepared plan and remains capacity-only and atomic.

Supported source values and byte geometries must round-trip coherently. Implementations must use checked arithmetic and return an explicit error for structural underflow, alignment, or encoded-field bounds they cannot convert. Unrelated protocol policy remains consumer-owned.

Macro adapters are supported only on direct built-in integer fixed fields that physically precede at least one range. This is a current hard ownership boundary: custom FixedCodec values or plans can require self-referential prepared storage. The adapter does not create a geometry getter; the ordinary source getter remains the raw wire integer. Unsigned bit projections may coexist with an adapter and read that whole integer; the adapter also consumes and returns the whole packed value.

Required Associated Types§

Source

type Error: Debug

Error returned when converting between the fixed representation and byte geometry.

Required Methods§

Source

fn to_bytes(value: C::Value<'_>) -> Result<usize, Self::Error>

Converts a decoded fixed source value to a byte length or absolute endpoint.

Source

fn from_bytes(bytes: usize) -> Result<C::Value<'static>, Self::Error>

Converts a byte length or absolute endpoint to an owned fixed source value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§