30 lines
566 B
Rust
30 lines
566 B
Rust
use std::fmt::Display;
|
|
|
|
use super::*;
|
|
|
|
struct Hex<'a> {
|
|
point: &'a Hash,
|
|
}
|
|
|
|
impl Display for Hex<'_> {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
for byte in self.point {
|
|
write!(f, "{byte:02x}")?
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
pub fn hex(point: &Hash) -> impl '_ + Display {
|
|
Hex { point }
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[test]
|
|
fn hex_test() {
|
|
assert_eq!(
|
|
hex(&(0..32).collect::<Vec<_>>().try_into().unwrap()).to_string(),
|
|
"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f",
|
|
);
|
|
}
|