Skip to content

Commit 30afc3e

Browse files
authored
Merge pull request #936 from umi-eng/nice-defmt-format-hardware-address
defmt Format hardware address the same as Display
2 parents ef67e7b + 1a59742 commit 30afc3e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/wire/ethernet.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ impl fmt::Display for EtherType {
2525

2626
/// A six-octet Ethernet II address.
2727
#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Default)]
28-
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
2928
pub struct Address(pub [u8; 6]);
3029

3130
impl Address {
@@ -79,6 +78,23 @@ impl fmt::Display for Address {
7978
}
8079
}
8180

81+
#[cfg(feature = "defmt")]
82+
impl defmt::Format for Address {
83+
fn format(&self, fmt: defmt::Formatter) {
84+
let bytes = self.0;
85+
defmt::write!(
86+
fmt,
87+
"{:02x}-{:02x}-{:02x}-{:02x}-{:02x}-{:02x}",
88+
bytes[0],
89+
bytes[1],
90+
bytes[2],
91+
bytes[3],
92+
bytes[4],
93+
bytes[5]
94+
)
95+
}
96+
}
97+
8298
/// A read/write wrapper around an Ethernet II frame buffer.
8399
#[derive(Debug, Clone)]
84100
#[cfg_attr(feature = "defmt", derive(defmt::Format))]

0 commit comments

Comments
 (0)