1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use std;
pub const MAC_LENGTH: usize = 6;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct MacAddress(pub [u8; MAC_LENGTH]);
pub type Vlan = u16;
pub type Port = u16;
impl std::fmt::Display for MacAddress {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}",
self.0[0], self.0[1], self.0[2], self.0[3], self.0[4], self.0[5],
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn format_mac_address() {
let mac = MacAddress([0u8, 1u8, 2u8, 3u8, 4u8, 5u8]);
assert_eq!(format!("{}", mac), "00:01:02:03:04:05".to_string());
}
}