solabi/fmt.rs
1//! Formatting helpers.
2
3use std::fmt::{self, Debug, Display, Formatter};
4
5/// A hexadecimal formater for byte slices.
6pub struct Hex<'a>(pub &'a [u8]);
7
8impl Debug for Hex<'_> {
9 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
10 Display::fmt(self, f)
11 }
12}
13
14impl Display for Hex<'_> {
15 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
16 f.write_str("0x")?;
17 for b in self.0 {
18 write!(f, "{b:02x}")?;
19 }
20 Ok(())
21 }
22}