Trait blart::BytesMapping

source ·
pub unsafe trait BytesMapping {
    type Domain;
    type Bytes: AsRef<[u8]>;

    // Required methods
    fn to_bytes(value: Self::Domain) -> Self::Bytes;
    fn from_bytes(bytes: Self::Bytes) -> Self::Domain;
}
Expand description

Trait representing a reversible conversion from a type to some sort of byte string, while preserving the ordering of the original type.

The ordering of the original type is determined by the Ord implementation, and the ordering of the byte string type is the lexicographic ordering.

The mapping should also maintain equality for the PartialEq and Eq implementations, along with hashing for the Hash implementation.

The following property should hold true:

value_a == value_b -> Mapping::to_bytes(value_a) == Mapping::to_bytes(value_b)

And this implies that the hash implementations should also match, in line with the Hash and Eq documentation.

Safety

This trait is unsafe because implementing it implies that the Mapped<Self> type will implement OrderedBytes, so the safety requirements must be upheld. Namely, that the ordering of values of the Self::Domain type must be equal to the ordering of those same values translated to the the Self::Bytes type.

Required Associated Types§

source

type Domain

The unconverted type that has a specific ordering

source

type Bytes: AsRef<[u8]>

The bytestring type that the Self::Domain is converted to.

Required Methods§

source

fn to_bytes(value: Self::Domain) -> Self::Bytes

Convert the domain type into the bytestring type

source

fn from_bytes(bytes: Self::Bytes) -> Self::Domain

Convert the bytestring type back into the domain type

Implementors§

source§

impl BytesMapping for ToBE<u8>

§

type Domain = u8

§

type Bytes = [u8; 1]

source§

impl BytesMapping for ToBE<u16>

§

type Domain = u16

§

type Bytes = [u8; 2]

source§

impl BytesMapping for ToBE<u32>

§

type Domain = u32

§

type Bytes = [u8; 4]

source§

impl BytesMapping for ToBE<u64>

§

type Domain = u64

§

type Bytes = [u8; 8]

source§

impl BytesMapping for ToBE<u128>

§

type Domain = u128

§

type Bytes = [u8; 16]

source§

impl BytesMapping for ToBE<usize>

§

type Domain = usize

§

type Bytes = [u8; 8]

source§

impl BytesMapping for ToBE<NonZeroU8>

§

type Domain = NonZeroU8

§

type Bytes = [u8; 1]

source§

impl BytesMapping for ToBE<NonZeroU16>

§

type Domain = NonZeroU16

§

type Bytes = [u8; 2]

source§

impl BytesMapping for ToBE<NonZeroU32>

§

type Domain = NonZeroU32

§

type Bytes = [u8; 4]

source§

impl BytesMapping for ToBE<NonZeroU64>

§

type Domain = NonZeroU64

§

type Bytes = [u8; 8]

source§

impl BytesMapping for ToBE<NonZeroU128>

§

type Domain = NonZeroU128

§

type Bytes = [u8; 16]

source§

impl BytesMapping for ToBE<NonZeroUsize>

§

type Domain = NonZeroUsize

§

type Bytes = [u8; 8]

source§

impl BytesMapping for ToOctets<Ipv4Addr>

§

type Bytes = [u8; 4]

§

type Domain = Ipv4Addr

source§

impl BytesMapping for ToOctets<Ipv6Addr>

§

type Bytes = [u8; 16]

§

type Domain = Ipv6Addr

source§

impl BytesMapping for ToUIntBE<i8>

§

type Domain = i8

§

type Bytes = [u8; 1]

source§

impl BytesMapping for ToUIntBE<i16>

§

type Domain = i16

§

type Bytes = [u8; 2]

source§

impl BytesMapping for ToUIntBE<i32>

§

type Domain = i32

§

type Bytes = [u8; 4]

source§

impl BytesMapping for ToUIntBE<i64>

§

type Domain = i64

§

type Bytes = [u8; 8]

source§

impl BytesMapping for ToUIntBE<i128>

§

type Domain = i128

§

type Bytes = [u8; 16]

source§

impl BytesMapping for ToUIntBE<isize>

§

type Domain = isize

§

type Bytes = [u8; 8]

source§

impl BytesMapping for ToUIntBE<NonZeroI8>

§

type Domain = NonZeroI8

§

type Bytes = [u8; 1]

source§

impl BytesMapping for ToUIntBE<NonZeroI16>

§

type Domain = NonZeroI16

§

type Bytes = [u8; 2]

source§

impl BytesMapping for ToUIntBE<NonZeroI32>

§

type Domain = NonZeroI32

§

type Bytes = [u8; 4]

source§

impl BytesMapping for ToUIntBE<NonZeroI64>

§

type Domain = NonZeroI64

§

type Bytes = [u8; 8]

source§

impl BytesMapping for ToUIntBE<NonZeroI128>

§

type Domain = NonZeroI128

§

type Bytes = [u8; 16]

source§

impl BytesMapping for ToUIntBE<NonZeroIsize>

§

type Domain = NonZeroIsize

§

type Bytes = [u8; 8]