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
41
42
43
44
45
46
47
48
49
50
51
52
pub trait Endianness: private::Sealed {
fn as_string() -> &'static str {
if Self::is_le() {
"LittleEndian"
} else {
"BigEndian"
}
}
fn is_le() -> bool;
fn is_be() -> bool;
}
#[derive(Debug)]
pub struct BigEndian;
#[derive(Debug)]
pub struct LittleEndian;
macro_rules! impl_endianness {
($type:ty, $le:expr) => {
impl Endianness for $type {
#[inline(always)]
fn is_le() -> bool {
$le
}
#[inline(always)]
fn is_be() -> bool {
!$le
}
}
};
}
impl_endianness!(BigEndian, false);
impl_endianness!(LittleEndian, true);
mod private {
pub trait Sealed {}
impl Sealed for super::BigEndian {}
impl Sealed for super::LittleEndian {}
}