From f085b1cbf81cd630dd103f11106c4f8d63b93c80 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Thu, 24 Dec 2020 13:02:40 +0100 Subject: [PATCH] xmpp-parsers/hashes: Simplify to_*_hex() functions. --- xmpp-parsers/src/hashes.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/xmpp-parsers/src/hashes.rs b/xmpp-parsers/src/hashes.rs index b80532e3..964719f0 100644 --- a/xmpp-parsers/src/hashes.rs +++ b/xmpp-parsers/src/hashes.rs @@ -151,20 +151,20 @@ impl Hash { /// Formats this hash into hexadecimal. pub fn to_hex(&self) -> String { - let mut bytes = vec![]; - for byte in self.hash.iter() { - bytes.push(format!("{:02x}", byte)); - } - bytes.join("") + self.hash + .iter() + .map(|byte| format!("{:02x}", byte)) + .collect::>() + .join("") } /// Formats this hash into colon-separated hexadecimal. pub fn to_colon_separated_hex(&self) -> String { - let mut bytes = vec![]; - for byte in self.hash.iter() { - bytes.push(format!("{:02x}", byte)); - } - bytes.join(":") + self.hash + .iter() + .map(|byte| format!("{:02x}", byte)) + .collect::>() + .join(":") } }