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§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".