From bd4525250ef73bd52a8a7b8040c58bf4b34b05d5 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Sat, 26 Oct 2024 11:59:06 +0200 Subject: [PATCH 1/2] Rename hex_impl to fmt_impl and reuse it for fmt::Debug --- src/fmt/debug.rs | 13 ++----------- src/fmt/hex.rs | 18 ++++-------------- src/fmt/mod.rs | 12 ++++++++++++ 3 files changed, 18 insertions(+), 25 deletions(-) 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..abd976fdf 100644 --- a/src/fmt/mod.rs +++ b/src/fmt/mod.rs @@ -1,4 +1,16 @@ +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) + } + } + }; +} + +#[macro_use] mod debug; +#[macro_use] mod hex; /// `BytesRef` is not a part of public API of bytes crate. From 5e06069569a93504a6866ac2f3450a3b1965d5f8 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Sat, 26 Oct 2024 15:59:31 +0200 Subject: [PATCH 2/2] Remove needless #[marco_use] --- src/fmt/mod.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/fmt/mod.rs b/src/fmt/mod.rs index abd976fdf..b8a0eafaf 100644 --- a/src/fmt/mod.rs +++ b/src/fmt/mod.rs @@ -8,9 +8,7 @@ macro_rules! fmt_impl { }; } -#[macro_use] mod debug; -#[macro_use] mod hex; /// `BytesRef` is not a part of public API of bytes crate.