summaryrefslogtreecommitdiffstats
path: root/vendor/bytes/src/fmt/hex.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/bytes/src/fmt/hex.rs')
-rw-r--r--vendor/bytes/src/fmt/hex.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/vendor/bytes/src/fmt/hex.rs b/vendor/bytes/src/fmt/hex.rs
new file mode 100644
index 000000000..97a749a33
--- /dev/null
+++ b/vendor/bytes/src/fmt/hex.rs
@@ -0,0 +1,37 @@
+use core::fmt::{Formatter, LowerHex, Result, UpperHex};
+
+use super::BytesRef;
+use crate::{Bytes, BytesMut};
+
+impl LowerHex for BytesRef<'_> {
+ fn fmt(&self, f: &mut Formatter<'_>) -> Result {
+ for &b in self.0 {
+ write!(f, "{:02x}", b)?;
+ }
+ Ok(())
+ }
+}
+
+impl UpperHex for BytesRef<'_> {
+ fn fmt(&self, f: &mut Formatter<'_>) -> Result {
+ for &b in self.0 {
+ write!(f, "{:02X}", b)?;
+ }
+ Ok(())
+ }
+}
+
+macro_rules! hex_impl {
+ ($tr:ident, $ty:ty) => {
+ impl $tr for $ty {
+ fn fmt(&self, f: &mut Formatter<'_>) -> Result {
+ $tr::fmt(&BytesRef(self.as_ref()), f)
+ }
+ }
+ };
+}
+
+hex_impl!(LowerHex, Bytes);
+hex_impl!(LowerHex, BytesMut);
+hex_impl!(UpperHex, Bytes);
+hex_impl!(UpperHex, BytesMut);