walker_common/utils/
hex.rs

1//! Handle "hex" encoding
2
3use std::fmt::{Debug, Formatter, LowerHex};
4
5pub struct Hex<'a>(pub &'a [u8]);
6
7impl Hex<'_> {
8    pub fn to_lower(&self) -> String {
9        format!("{self:x}")
10    }
11}
12
13impl Debug for Hex<'_> {
14    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
15        write!(f, "{self:x}")
16    }
17}
18
19impl LowerHex for Hex<'_> {
20    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
21        for b in self.0 {
22            write!(f, "{:02x}", b)?;
23        }
24        Ok(())
25    }
26}