use std::fmt::{Debug, Display, Error, Formatter};
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout, Ref, Unaligned};
#[derive(Debug, Eq, PartialEq, Hash, thiserror::Error)]
pub struct WrongSize;
impl Display for WrongSize {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
<Self as Debug>::fmt(self, f)
}
}
#[derive(
Debug, Eq, PartialEq, Hash, Copy, Clone, KnownLayout, FromBytes, IntoBytes, Immutable, Unaligned,
)]
#[repr(C)]
#[derive(Default)]
pub struct EUI64(pub [u8; 8]);
impl<'a> std::convert::From<&'a EUI64> for &'a [u8] {
fn from(val: &'a EUI64) -> Self {
&val.0
}
}
impl<'a> std::convert::TryInto<&'a EUI64> for &'a [u8] {
type Error = WrongSize;
fn try_into(self) -> Result<&'a EUI64, Self::Error> {
Ref::<_, EUI64>::from_bytes(self)
.map_err(Into::into)
.map_err(|_: zerocopy::SizeError<_, _>| WrongSize)
.map(Ref::into_ref)
}
}
#[derive(
Debug, Eq, PartialEq, Hash, Copy, Clone, KnownLayout, FromBytes, IntoBytes, Immutable, Unaligned,
)]
#[repr(C)]
#[derive(Default)]
pub struct EUI48(pub [u8; 6]);
impl<'a> std::convert::From<&'a EUI48> for &'a [u8] {
fn from(val: &'a EUI48) -> Self {
&val.0
}
}
impl<'a> std::convert::TryInto<&'a EUI48> for &'a [u8] {
type Error = WrongSize;
fn try_into(self) -> Result<&'a EUI48, Self::Error> {
Ref::<_, EUI48>::from_bytes(self)
.map_err(Into::into)
.map_err(|_: zerocopy::SizeError<_, _>| WrongSize)
.map(Ref::into_ref)
}
}