You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
503 B
24 lines
503 B
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); |
|
} |
|
}
|
|
|