From f63cb85f937c5319bb9f28949dea46e3ca990ccc Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 27 Sep 2019 15:20:51 +0100 Subject: [PATCH] net_util: Implement fmt::Display for MacAddr Updated clippy does not like the declaration of a "to_string()" function and instead requires fmt::Display to be implemented. Signed-off-by: Rob Bradford --- net_util/src/mac.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/net_util/src/mac.rs b/net_util/src/mac.rs index cb6cdb805..53dc20dbb 100644 --- a/net_util/src/mac.rs +++ b/net_util/src/mac.rs @@ -6,6 +6,7 @@ // found in the THIRD-PARTY file. use rand::Rng; +use std::fmt; use std::result::Result; use serde::de::{Deserialize, Deserializer, Error}; @@ -66,14 +67,6 @@ impl MacAddr { &self.bytes } - pub fn to_string(self) -> String { - let b = &self.bytes; - format!( - "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", - b[0], b[1], b[2], b[3], b[4], b[5] - ) - } - pub fn local_random() -> MacAddr { // Generate a fully random MAC let mut random_bytes = rand::thread_rng().gen::<[u8; MAC_ADDR_LEN]>(); @@ -87,6 +80,17 @@ impl MacAddr { } } +impl fmt::Display for MacAddr { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let b = &self.bytes; + write!( + f, + "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", + b[0], b[1], b[2], b[3], b[4], b[5] + ) + } +} + impl Serialize for MacAddr { fn serialize(&self, serializer: S) -> Result where