uts_core/utils/hex.rs
1use core::fmt;
2
3/// Zero-allocation wrapper that displays byte slices as lowercase hex.
4pub struct Hexed<'a, T: ?Sized>(pub &'a T);
5
6impl<'a, T: ?Sized + AsRef<[u8]>> fmt::Display for Hexed<'a, T> {
7 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8 for b in self.0.as_ref() {
9 write!(f, "{:02x}", b)?;
10 }
11 Ok(())
12 }
13}
14
15impl<'a, T: ?Sized + AsRef<[u8]>> fmt::Debug for Hexed<'a, T> {
16 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17 fmt::Display::fmt(self, f)
18 }
19}