xray_tracing/
hexbytes.rs

1use std::fmt;
2
3/// Wraps a byte slice to enable lowcast hex display formatting
4pub(crate) struct Bytes<'a>(pub(crate) &'a [u8]);
5
6impl fmt::LowerHex for Bytes<'_> {
7    fn fmt(
8        &self,
9        fmt: &mut fmt::Formatter<'_>,
10    ) -> fmt::Result {
11        for byte in self.0 {
12            fmt.write_fmt(format_args!("{:02x}", byte))?
13        }
14        Ok(())
15    }
16}
17
18#[cfg(test)]
19mod tests {
20    use super::Bytes;
21    #[test]
22    fn formats_lowerhex() {
23        assert_eq!(format!("{:x}", Bytes(b"test")), "74657374")
24    }
25}