1#[derive(PartialEq, Eq, Copy, Debug, Clone)]
2pub enum Endian {
4 Little,
5 Big,
6}
7
8pub const LE: Endian = Endian::Little;
10pub const BE: Endian = Endian::Big;
12pub const NETWORK: Endian = Endian::Big;
14#[cfg(target_endian = "little")]
15pub const NATIVE: Endian = LE;
17#[cfg(target_endian = "big")]
18pub const NATIVE: Endian = BE;
20
21impl Default for Endian {
22 #[inline]
23 fn default() -> Self {
24 NATIVE
25 }
26}
27
28impl From<bool> for Endian {
29 #[inline]
30 fn from(little_endian: bool) -> Self {
31 if little_endian {
32 LE
33 } else {
34 BE
35 }
36 }
37}
38
39impl Endian {
40 #[inline]
41 pub fn network() -> Endian {
42 NETWORK
43 }
44 #[inline]
45 pub fn is_little(&self) -> bool {
46 *self == LE
47 }
48}