mod private {
pub trait Endianness: 'static + Send + Sync + Copy {
const _NAME: &'static str;
const _IS_LITTLE: bool;
const _IS_BIG: bool;
}
}
impl<T: private::Endianness> Endianness for T {
const NAME: &'static str = T::_NAME;
const IS_LITTLE: bool = T::_IS_LITTLE;
const IS_BIG: bool = T::_IS_BIG;
}
pub trait Endianness: private::Endianness {
const NAME: &'static str;
const IS_LITTLE: bool;
const IS_BIG: bool;
}
impl core::fmt::Display for LE {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(LE::NAME)
}
}
impl core::fmt::Display for BE {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(BE::NAME)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct LittleEndian;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct BigEndian;
impl private::Endianness for LittleEndian {
const _NAME: &'static str = "little";
const _IS_LITTLE: bool = true;
const _IS_BIG: bool = false;
}
impl private::Endianness for BigEndian {
const _NAME: &'static str = "big";
const _IS_LITTLE: bool = false;
const _IS_BIG: bool = true;
}
pub type BE = BigEndian;
pub type LE = LittleEndian;
#[cfg(target_endian = "little")]
pub type NativeEndian = LittleEndian;
#[cfg(target_endian = "big")]
pub type NativeEndian = BigEndian;
pub type NE = NativeEndian;