pub trait ToOrderableBytes {
type Bytes: AsRef<[u8]>;
const ENCODED_LEN: usize;
// Required method
fn to_orderable_bytes(&self) -> Self::Bytes;
}Expand description
Maps a value to its canonical, order-preserving fixed-length byte encoding.
Implementors guarantee, for any a and b of the implementing type:
- Equality: byte equality of the outputs agrees with the type’s
value equality (
a.to_orderable_bytes() == b.to_orderable_bytes()iffa == b). - Order: byte-wise lexicographic comparison of the outputs agrees
with the type’s natural total order
(
a.to_orderable_bytes() <= b.to_orderable_bytes()iffa <= b).
The encoded length is fixed per type and exposed via
ENCODED_LEN. Per-type modules also re-export
the same value as a free pub const for use in const contexts where
naming the impl would be unwieldy.
Required Associated Constants§
Sourceconst ENCODED_LEN: usize
const ENCODED_LEN: usize
Length, in bytes, of the canonical encoding produced by
to_orderable_bytes.
Required Associated Types§
Sourcetype Bytes: AsRef<[u8]>
type Bytes: AsRef<[u8]>
The fixed-length byte array type returned by
to_orderable_bytes. By convention
every impl sets this to [u8; Self::ENCODED_LEN]; the
indirection through an associated type is only needed because
stable Rust does not yet allow naming [u8; Self::ENCODED_LEN]
directly in a method signature (that requires
feature(generic_const_exprs)).
Required Methods§
Sourcefn to_orderable_bytes(&self) -> Self::Bytes
fn to_orderable_bytes(&self) -> Self::Bytes
Build the canonical, order-preserving fixed-length byte encoding
of self.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".