nandi/rustnimpublic Fork 0
main
Commits
Clone
git clone https://git.rickub.com/nandi/rustnim.git
git clone ssh://git@rickub.com/nandi/rustnim.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

display.rs · 35 lines · 864 BRust Blame HistoryRaw
Add display.rs and the alloc half: all of base16ct now goes through afb2a6e nandithebull 6h ago1use core::fmt;
2
3/// `core::fmt` presenter for binary data encoded as hexadecimal (Base16).
4#[derive(Copy, Clone, Debug, Eq, PartialEq)]
5pub struct HexDisplay<'a>(pub &'a [u8]);
6
7impl fmt::Display for HexDisplay<'_> {
8 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9 write!(f, "{self:X}")
10 }
11}
12
13impl fmt::UpperHex for HexDisplay<'_> {
14 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
15 let mut hex = [0u8; 2];
16
17 for &byte in self.0 {
18 f.write_str(crate::upper::encode_str(&[byte], &mut hex)?)?;
19 }
20
21 Ok(())
22 }
23}
24
25impl fmt::LowerHex for HexDisplay<'_> {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 let mut hex = [0u8; 2];
28
29 for &byte in self.0 {
30 f.write_str(crate::lower::encode_str(&[byte], &mut hex)?)?;
31 }
32
33 Ok(())
34 }
35}