From a1489a64289137bdf9c36c53ef3ab4cfb8939d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Wed, 23 Oct 2019 15:03:30 +0200 Subject: [PATCH] xmpp-rs: Use to_hex conversion from struct directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- xmpp-rs/src/pubsub/avatar.rs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/xmpp-rs/src/pubsub/avatar.rs b/xmpp-rs/src/pubsub/avatar.rs index 1a8627a..bdfccea 100644 --- a/xmpp-rs/src/pubsub/avatar.rs +++ b/xmpp-rs/src/pubsub/avatar.rs @@ -12,7 +12,6 @@ use std::io::{self, Write}; use tokio_xmpp::Packet; use xmpp_parsers::{ avatar::{Data, Metadata}, - hashes::Hash, iq::Iq, ns, pubsub::{ @@ -23,15 +22,6 @@ use xmpp_parsers::{ Jid, }; -// TODO: Update xmpp-parsers to get this function for free on Hash. -fn hash_to_hex(hash: &Hash) -> String { - let mut bytes = vec![]; - for byte in hash.hash.iter() { - bytes.push(format!("{:02x}", byte)); - } - bytes.join("") -} - pub(crate) fn handle_metadata_pubsub_event( from: &Jid, tx: &mut mpsc::UnboundedSender, @@ -43,7 +33,7 @@ pub(crate) fn handle_metadata_pubsub_event( if payload.is("metadata", ns::AVATAR_METADATA) { let metadata = Metadata::try_from(payload).unwrap(); for info in metadata.infos { - let filename = format!("data/{}/{}", from, hash_to_hex(&*info.id)); + let filename = format!("data/{}/{}", from, &*info.id.to_hex()); let file_length = match fs::metadata(filename.clone()) { Ok(metadata) => metadata.len(), Err(_) => 0,