1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Provides types and traits for representing endianness of an integer encoding.

mod sealed {
    pub trait Sealed {}
}

/// Represents endianness of an integer encoding.
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub enum Endian {
    /// Little-endian representation.
    Little,
    /// Big-endian representation.
    Big,
}

/// Trait for types that represent fixed endianness.
pub trait FixedEndian: sealed::Sealed + Copy {
    /// Fixed endianness value of the type.
    const ENDIAN: Endian;
}

/// Represents big endian integer encoding.
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct BigEndian;

impl sealed::Sealed for BigEndian {}

impl FixedEndian for BigEndian {
    const ENDIAN: Endian = Endian::Big;
}

/// Represents little endian integer encoding.
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct LittleEndian;

impl sealed::Sealed for LittleEndian {}

impl FixedEndian for LittleEndian {
    const ENDIAN: Endian = Endian::Little;
}