#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Endian {
Big,
Little,
}
#[cfg(target_endian = "big")]
const NATIVE_ENDIAN: Endian = Endian::Big;
#[cfg(target_endian = "little")]
const NATIVE_ENDIAN: Endian = Endian::Little;
impl Endian {
pub const NATIVE: Self = NATIVE_ENDIAN;
pub const fn is(self, other: Self) -> bool {
self as u8 == other as u8
}
pub const fn reverse(self) -> Self {
match self {
Self::Big => Self::Little,
Self::Little => Self::Big,
}
}
pub const fn native_or_reversed(reverse: bool) -> Self {
if reverse {
Self::NATIVE.reverse()
} else {
Self::NATIVE
}
}
}
impl std::ops::Not for Endian {
type Output = Self;
fn not(self) -> Self::Output {
self.reverse()
}
}