Skip to content

Commit 54f1c26

Browse files
authored
Rename hex_impl! to fmt_impl! and reuse it for fmt::Debug (#743)
1 parent 4cd8969 commit 54f1c26

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

src/fmt/debug.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,5 @@ impl Debug for BytesRef<'_> {
3636
}
3737
}
3838

39-
impl Debug for Bytes {
40-
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
41-
Debug::fmt(&BytesRef(self.as_ref()), f)
42-
}
43-
}
44-
45-
impl Debug for BytesMut {
46-
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
47-
Debug::fmt(&BytesRef(self.as_ref()), f)
48-
}
49-
}
39+
fmt_impl!(Debug, Bytes);
40+
fmt_impl!(Debug, BytesMut);

src/fmt/hex.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,7 @@ impl UpperHex for BytesRef<'_> {
2121
}
2222
}
2323

24-
macro_rules! hex_impl {
25-
($tr:ident, $ty:ty) => {
26-
impl $tr for $ty {
27-
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
28-
$tr::fmt(&BytesRef(self.as_ref()), f)
29-
}
30-
}
31-
};
32-
}
33-
34-
hex_impl!(LowerHex, Bytes);
35-
hex_impl!(LowerHex, BytesMut);
36-
hex_impl!(UpperHex, Bytes);
37-
hex_impl!(UpperHex, BytesMut);
24+
fmt_impl!(LowerHex, Bytes);
25+
fmt_impl!(LowerHex, BytesMut);
26+
fmt_impl!(UpperHex, Bytes);
27+
fmt_impl!(UpperHex, BytesMut);

src/fmt/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
macro_rules! fmt_impl {
2+
($tr:ident, $ty:ty) => {
3+
impl $tr for $ty {
4+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
5+
$tr::fmt(&BytesRef(self.as_ref()), f)
6+
}
7+
}
8+
};
9+
}
10+
111
mod debug;
212
mod hex;
313

0 commit comments

Comments
 (0)