use std::fmt; pub struct Hexlify<'b>(pub &'b [u8]); impl<'a> fmt::LowerHex for Hexlify<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for byte in self.0.iter() { write!(f, "{:02x}", byte)?; } Ok(()) } } #[cfg(test)] mod tests { use super::*; #[test] fn test_hexlify() { let data = b"\x5a\x6b\x23\x4f\xa3\x7f\x9e"; let result = "5a6b234fa37f9e"; assert_eq!(format!("{:x}", Hexlify(data)), result); } }