dsi_bitstream/traits/
endianness.rs1mod private {
12 pub trait Endianness: 'static + Send + Sync + Copy {
14 const _NAME: &'static str;
16 const _IS_LITTLE: bool;
18 const _IS_BIG: bool;
20 }
21}
22
23impl<T: private::Endianness> Endianness for T {
24 const NAME: &'static str = T::_NAME;
25 const IS_LITTLE: bool = T::_IS_LITTLE;
26 const IS_BIG: bool = T::_IS_BIG;
27}
28
29pub trait Endianness: private::Endianness {
37 const NAME: &'static str;
39 const IS_LITTLE: bool;
41 const IS_BIG: bool;
43}
44
45impl core::fmt::Display for LE {
46 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
47 f.write_str(LE::NAME)
48 }
49}
50
51impl core::fmt::Display for BE {
52 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
53 f.write_str(BE::NAME)
54 }
55}
56
57#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
59pub struct LittleEndian;
60
61#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
63pub struct BigEndian;
64
65impl private::Endianness for LittleEndian {
66 const _NAME: &'static str = "little";
67 const _IS_LITTLE: bool = true;
68 const _IS_BIG: bool = false;
69}
70
71impl private::Endianness for BigEndian {
72 const _NAME: &'static str = "big";
73 const _IS_LITTLE: bool = false;
74 const _IS_BIG: bool = true;
75}
76
77pub type BE = BigEndian;
79
80pub type LE = LittleEndian;
82
83#[cfg(target_endian = "little")]
84pub type NativeEndian = LittleEndian;
86#[cfg(target_endian = "big")]
87pub type NativeEndian = BigEndian;
89
90pub type NE = NativeEndian;