#![no_std]
#![allow(clippy::wrong_self_convention)]
pub use endify_derive::Endify;
pub trait Endify {
fn to_le(self) -> Self;
fn to_be(self) -> Self;
fn from_le(self) -> Self;
fn from_be(self) -> Self;
}
macro_rules! impl_noop {
($($t:ty),+) => {
$(
impl Endify for $t {
fn to_le(self) -> Self {
self
}
fn to_be(self) -> Self {
self
}
fn from_le(self) -> Self {
self
}
fn from_be(self) -> Self {
self
}
}
)+
};
}
macro_rules! impl_primitive {
($($t:ty), +) => {
$(
impl Endify for $t {
fn to_le(self) -> Self {
<$t>::to_le(self)
}
fn to_be(self) -> Self {
<$t>::to_be(self)
}
fn from_le(self) -> Self {
<$t>::from_le(self)
}
fn from_be(self) -> Self {
<$t>::from_be(self)
}
}
)+
};
}
impl<T: Endify, const N: usize> Endify for [T; N] {
fn to_le(self) -> Self {
self.map(Endify::to_le)
}
fn to_be(self) -> Self {
self.map(Endify::to_be)
}
fn from_le(self) -> Self {
self.map(Endify::from_le)
}
fn from_be(self) -> Self {
self.map(Endify::from_be)
}
}
impl_noop!(u8, i8, bool);
impl_primitive!(u16, i16, u32, i32, u64, i64, u128, i128);