mac: impl Debug and Display for MacAddress

Adding implementations of the `Debug` and `Display` traits to the
`MacAddress` struct allows creating string representations of these
objects.
master
Dustin 2018-09-29 11:39:19 -05:00
parent ff8316895a
commit 989a6eb0e6
1 changed files with 12 additions and 0 deletions

View File

@ -37,6 +37,7 @@ impl error::Error for ParseError {
} }
#[derive(Debug)]
pub struct MacAddress { pub struct MacAddress {
addr: [u8; 6], addr: [u8; 6],
} }
@ -67,6 +68,17 @@ impl MacAddress {
} }
impl fmt::Display for MacAddress {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = self.addr.iter()
.map(|b| format!("{:x}", b))
.collect::<Vec<_>>()
.join(":");
write!(f, "{}", s)
}
}
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;