1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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",
    );
}