format_struct/
endian.rs

1//! Provides types and traits for representing endianness of an integer encoding.
2
3mod sealed {
4    pub trait Sealed {}
5}
6
7/// Represents endianness of an integer encoding.
8#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
9pub enum Endian {
10    /// Little-endian representation.
11    Little,
12    /// Big-endian representation.
13    Big,
14}
15
16/// Trait for types that represent fixed endianness.
17pub trait FixedEndian: sealed::Sealed + Copy {
18    /// Fixed endianness value of the type.
19    const ENDIAN: Endian;
20}
21
22/// Represents big endian integer encoding.
23#[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)]
24pub struct BigEndian;
25
26impl sealed::Sealed for BigEndian {}
27
28impl FixedEndian for BigEndian {
29    const ENDIAN: Endian = Endian::Big;
30}
31
32/// Represents little endian integer encoding.
33#[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)]
34pub struct LittleEndian;
35
36impl sealed::Sealed for LittleEndian {}
37
38impl FixedEndian for LittleEndian {
39    const ENDIAN: Endian = Endian::Little;
40}