pub trait CountPrefix: Bits + Sealed {
// Required methods
fn try_from_count(len: usize) -> Result<Self, WidthError>
where Self: Sized;
fn to_count(self) -> usize;
}Expand description
Checked length ⇄ wire-prefix conversions: the types usable as a length/count prefix —
by the #[brw(count_prefix = <Ty>)] directive and by the
codecs::prefixed string codec.
The prefix is computed from len() on encode and turned back into an element count on
decode. try_from_count is checked and never truncates: the length is widened (never
narrowed) before the range compare, so 300 elements against a u8 prefix is
WidthError::ValueTooLarge — not a silently wrapped 44.
Required Methods§
Sourcefn try_from_count(len: usize) -> Result<Self, WidthError>where
Self: Sized,
fn try_from_count(len: usize) -> Result<Self, WidthError>where
Self: Sized,
The prefix for a collection of len elements, or [WidthError::ValueTooLarge] when
len exceeds the prefix’s range.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".