thruput_sdk/hex.rs
1//! Lowercase hex formatting for opaque payload bytes.
2//!
3//! Use [`crate::base58_encode`] for addresses and typed hashes.
4
5use core::fmt;
6
7pub struct Hex<'a>(&'a [u8]);
8
9impl<'a> fmt::Display for Hex<'a> {
10 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
11 for b in self.0 {
12 write!(f, "{:02x}", b)?;
13 }
14 Ok(())
15 }
16}
17
18pub fn hex_encode<'a, B: AsRef<[u8]>>(b: &'a B) -> Hex<'a> {
19 Hex(b.as_ref())
20}