summaryrefslogtreecommitdiffstats
path: root/vendor/base16ct/src/display.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:41 +0000
commit10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch)
treebdffd5d80c26cf4a7a518281a204be1ace85b4c1 /vendor/base16ct/src/display.rs
parentReleasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff)
downloadrustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.tar.xz
rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.zip
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/base16ct/src/display.rs')
-rw-r--r--vendor/base16ct/src/display.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/vendor/base16ct/src/display.rs b/vendor/base16ct/src/display.rs
new file mode 100644
index 000000000..1397a91dd
--- /dev/null
+++ b/vendor/base16ct/src/display.rs
@@ -0,0 +1,35 @@
+use core::fmt;
+
+/// `core::fmt` presenter for binary data encoded as hexadecimal (Base16).
+#[derive(Copy, Clone, Debug, Eq, PartialEq)]
+pub struct HexDisplay<'a>(pub &'a [u8]);
+
+impl fmt::Display for HexDisplay<'_> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "{:X}", self)
+ }
+}
+
+impl fmt::UpperHex for HexDisplay<'_> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let mut hex = [0u8; 2];
+
+ for &byte in self.0 {
+ f.write_str(crate::upper::encode_str(&[byte], &mut hex)?)?;
+ }
+
+ Ok(())
+ }
+}
+
+impl fmt::LowerHex for HexDisplay<'_> {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let mut hex = [0u8; 2];
+
+ for &byte in self.0 {
+ f.write_str(crate::lower::encode_str(&[byte], &mut hex)?)?;
+ }
+
+ Ok(())
+ }
+}