diff --git a/src/fmt/debug.rs b/src/fmt/debug.rs index 83de695dd..82d0aa5e3 100644 --- a/src/fmt/debug.rs +++ b/src/fmt/debug.rs @@ -36,14 +36,5 @@ impl Debug for BytesRef<'_> { } } -impl Debug for Bytes { - fn fmt(&self, f: &mut Formatter<'_>) -> Result { - Debug::fmt(&BytesRef(self.as_ref()), f) - } -} - -impl Debug for BytesMut { - fn fmt(&self, f: &mut Formatter<'_>) -> Result { - Debug::fmt(&BytesRef(self.as_ref()), f) - } -} +fmt_impl!(Debug, Bytes); +fmt_impl!(Debug, BytesMut); diff --git a/src/fmt/hex.rs b/src/fmt/hex.rs index 97a749a33..1203b4198 100644 --- a/src/fmt/hex.rs +++ b/src/fmt/hex.rs @@ -21,17 +21,7 @@ impl UpperHex for BytesRef<'_> { } } -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); +fmt_impl!(LowerHex, Bytes); +fmt_impl!(LowerHex, BytesMut); +fmt_impl!(UpperHex, Bytes); +fmt_impl!(UpperHex, BytesMut); diff --git a/src/fmt/mod.rs b/src/fmt/mod.rs index 676d15fc2..b8a0eafaf 100644 --- a/src/fmt/mod.rs +++ b/src/fmt/mod.rs @@ -1,3 +1,13 @@ +macro_rules! fmt_impl { + ($tr:ident, $ty:ty) => { + impl $tr for $ty { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + $tr::fmt(&BytesRef(self.as_ref()), f) + } + } + }; +} + mod debug; mod hex;