#![deny(unsafe_code, missing_docs, warnings)]
pub use core::net::Ipv4Addr;
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Debug, Hash, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct MacAddress {
pub octets: [u8; 6],
}
impl MacAddress {
#[allow(clippy::many_single_char_names)]
pub const fn new(a: u8, b: u8, c: u8, d: u8, e: u8, f: u8) -> MacAddress {
MacAddress {
octets: [a, b, c, d, e, f],
}
}
pub const fn octets(&self) -> [u8; 6] {
[
self.octets[0],
self.octets[1],
self.octets[2],
self.octets[3],
self.octets[4],
self.octets[5],
]
}
pub const UNSPECIFIED: Self = MacAddress::new(0, 0, 0, 0, 0, 0);
}
impl From<[u8; 6]> for MacAddress {
fn from(octets: [u8; 6]) -> MacAddress {
MacAddress::new(
octets[0], octets[1], octets[2], octets[3], octets[4], octets[5],
)
}
}
impl ::core::fmt::Display for MacAddress {
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
write!(
fmt,
"{:02X}:{:02X}:{:02X}:{:02X}:{:02X}:{:02X}",
self.octets[0],
self.octets[1],
self.octets[2],
self.octets[3],
self.octets[4],
self.octets[5],
)
}
}