Skip to main content

ToOrderableBytes

Trait ToOrderableBytes 

Source
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() iff a == 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() iff a <= 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§

Source

const ENCODED_LEN: usize

Length, in bytes, of the canonical encoding produced by to_orderable_bytes.

Required Associated Types§

Source

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§

Source

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".

Implementations on Foreign Types§

Source§

impl ToOrderableBytes for bool

Source§

impl ToOrderableBytes for char

Source§

impl ToOrderableBytes for f32

Source§

impl ToOrderableBytes for f64

Source§

impl ToOrderableBytes for i8

Source§

impl ToOrderableBytes for i16

Source§

impl ToOrderableBytes for i32

Source§

impl ToOrderableBytes for i64

Source§

impl ToOrderableBytes for i128

Source§

impl ToOrderableBytes for u8

Source§

impl ToOrderableBytes for u16

Source§

impl ToOrderableBytes for u32

Source§

impl ToOrderableBytes for u64

Source§

impl ToOrderableBytes for u128

Implementors§