From e6b37c1c5fc2beb001111289b0ab9a4d56c6478a Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 3 Jun 2025 13:02:44 +0300 Subject: [PATCH] implement `Display` trait for `InfoHash` #226 --- crates/udp_protocol/src/common.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/udp_protocol/src/common.rs b/crates/udp_protocol/src/common.rs index 01e5b1c..7842657 100644 --- a/crates/udp_protocol/src/common.rs +++ b/crates/udp_protocol/src/common.rs @@ -275,6 +275,19 @@ pub fn invalid_data() -> ::std::io::Error { ::std::io::Error::new(::std::io::ErrorKind::InvalidData, "invalid data") } +impl std::fmt::Display for InfoHash { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + self.0 + .iter() + .map(|b| format!("{:02x}", b)) + .collect::() + ) + } +} + #[cfg(test)] impl quickcheck::Arbitrary for InfoHash { fn arbitrary(g: &mut quickcheck::Gen) -> Self {