1
0
mirror of https://gitlab.com/xmpp-rs/xmpp-rs.git synced 2024-07-03 11:50:35 +02:00

xmpp-parsers/hashes: Simplify to_*_hex() functions.

This commit is contained in:
Emmanuel Gil Peyrot 2020-12-24 13:02:40 +01:00 committed by Link Mauve
parent f6cb4a8080
commit f085b1cbf8

View File

@ -151,20 +151,20 @@ impl Hash {
/// Formats this hash into hexadecimal. /// Formats this hash into hexadecimal.
pub fn to_hex(&self) -> String { pub fn to_hex(&self) -> String {
let mut bytes = vec![]; self.hash
for byte in self.hash.iter() { .iter()
bytes.push(format!("{:02x}", byte)); .map(|byte| format!("{:02x}", byte))
} .collect::<Vec<_>>()
bytes.join("") .join("")
} }
/// Formats this hash into colon-separated hexadecimal. /// Formats this hash into colon-separated hexadecimal.
pub fn to_colon_separated_hex(&self) -> String { pub fn to_colon_separated_hex(&self) -> String {
let mut bytes = vec![]; self.hash
for byte in self.hash.iter() { .iter()
bytes.push(format!("{:02x}", byte)); .map(|byte| format!("{:02x}", byte))
} .collect::<Vec<_>>()
bytes.join(":") .join(":")
} }
} }