pub trait Integer<const BYTES: usize> {
fn from_be_bytes(bytes: [u8; BYTES]) -> Self;
fn from_le_bytes(bytes: [u8; BYTES]) -> Self;
fn from_ne_bytes(bytes: [u8; BYTES]) -> Self;
}
impl Integer<1> for u8 {
fn from_be_bytes(bytes: [u8; 1]) -> Self {
Self::from_be_bytes(bytes)
}
fn from_le_bytes(bytes: [u8; 1]) -> Self {
Self::from_le_bytes(bytes)
}
fn from_ne_bytes(bytes: [u8; 1]) -> Self {
Self::from_ne_bytes(bytes)
}
}
impl Integer<2> for u16 {
fn from_be_bytes(bytes: [u8; 2]) -> Self {
Self::from_be_bytes(bytes)
}
fn from_le_bytes(bytes: [u8; 2]) -> Self {
Self::from_le_bytes(bytes)
}
fn from_ne_bytes(bytes: [u8; 2]) -> Self {
Self::from_ne_bytes(bytes)
}
}
impl Integer<4> for u32 {
fn from_be_bytes(bytes: [u8; 4]) -> Self {
Self::from_be_bytes(bytes)
}
fn from_le_bytes(bytes: [u8; 4]) -> Self {
Self::from_le_bytes(bytes)
}
fn from_ne_bytes(bytes: [u8; 4]) -> Self {
Self::from_ne_bytes(bytes)
}
}
impl Integer<8> for u64 {
fn from_be_bytes(bytes: [u8; 8]) -> Self {
Self::from_be_bytes(bytes)
}
fn from_le_bytes(bytes: [u8; 8]) -> Self {
Self::from_le_bytes(bytes)
}
fn from_ne_bytes(bytes: [u8; 8]) -> Self {
Self::from_ne_bytes(bytes)
}
}
impl Integer<16> for u128 {
fn from_be_bytes(bytes: [u8; 16]) -> Self {
Self::from_be_bytes(bytes)
}
fn from_le_bytes(bytes: [u8; 16]) -> Self {
Self::from_le_bytes(bytes)
}
fn from_ne_bytes(bytes: [u8; 16]) -> Self {
Self::from_ne_bytes(bytes)
}
}
impl Integer<1> for i8 {
fn from_be_bytes(bytes: [u8; 1]) -> Self {
Self::from_be_bytes(bytes)
}
fn from_le_bytes(bytes: [u8; 1]) -> Self {
Self::from_le_bytes(bytes)
}
fn from_ne_bytes(bytes: [u8; 1]) -> Self {
Self::from_ne_bytes(bytes)
}
}
impl Integer<2> for i16 {
fn from_be_bytes(bytes: [u8; 2]) -> Self {
Self::from_be_bytes(bytes)
}
fn from_le_bytes(bytes: [u8; 2]) -> Self {
Self::from_le_bytes(bytes)
}
fn from_ne_bytes(bytes: [u8; 2]) -> Self {
Self::from_ne_bytes(bytes)
}
}
impl Integer<4> for i32 {
fn from_be_bytes(bytes: [u8; 4]) -> Self {
Self::from_be_bytes(bytes)
}
fn from_le_bytes(bytes: [u8; 4]) -> Self {
Self::from_le_bytes(bytes)
}
fn from_ne_bytes(bytes: [u8; 4]) -> Self {
Self::from_ne_bytes(bytes)
}
}
impl Integer<8> for i64 {
fn from_be_bytes(bytes: [u8; 8]) -> Self {
Self::from_be_bytes(bytes)
}
fn from_le_bytes(bytes: [u8; 8]) -> Self {
Self::from_le_bytes(bytes)
}
fn from_ne_bytes(bytes: [u8; 8]) -> Self {
Self::from_ne_bytes(bytes)
}
}
impl Integer<16> for i128 {
fn from_be_bytes(bytes: [u8; 16]) -> Self {
Self::from_be_bytes(bytes)
}
fn from_le_bytes(bytes: [u8; 16]) -> Self {
Self::from_le_bytes(bytes)
}
fn from_ne_bytes(bytes: [u8; 16]) -> Self {
Self::from_ne_bytes(bytes)
}
}