#[repr(C, packed)]
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
#[derive(Deserialize, Serialize)]
pub struct InternetCheckSum(NetworkEndianU16);
impl Into<NetworkEndianU16> for InternetCheckSum
{
#[inline(always)]
fn into(self) -> NetworkEndianU16
{
self.0
}
}
impl Into<u16> for InternetCheckSum
{
#[inline(always)]
fn into(self) -> u16
{
self.0.to_native_endian()
}
}
impl From<NetworkEndianU16> for InternetCheckSum
{
#[inline(always)]
fn from(value: NetworkEndianU16) -> Self
{
InternetCheckSum(value)
}
}
impl From<u16> for InternetCheckSum
{
#[inline(always)]
fn from(value: u16) -> Self
{
InternetCheckSum(NetworkEndianU16::from_native_endian(value))
}
}
impl Display for InternetCheckSum
{
#[inline(always)]
fn fmt(&self, f: &mut Formatter) -> fmt::Result
{
write!(f, "0x{:04X}", self.0.to_native_endian())
}
}
impl Debug for InternetCheckSum
{
#[inline(always)]
fn fmt(&self, f: &mut Formatter) -> fmt::Result
{
write!(f, "0x{:04X}", self.0.to_native_endian())
}
}
impl Default for InternetCheckSum
{
#[inline(always)]
fn default() -> Self
{
InternetCheckSum(NetworkEndianU16::Zero)
}
}
impl InternetCheckSum
{
#[inline(always)]
pub fn to_network_endian(self) -> u16
{
self.0.to_network_endian()
}
}