Skip to content

Commit 169b15b

Browse files
committed
Implement Debug for Padding
Use the `MaybeUninit` formatting so this prints as `Padding<u32>` or similar. (backport <#4711>) (cherry picked from commit 4c95aea)
1 parent 4a46fbe commit 169b15b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/types.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ impl<T: Copy> Default for Padding<T> {
1717
}
1818
}
1919

20+
impl<T: Copy> fmt::Debug for Padding<T> {
21+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22+
// Taken frmo `MaybeUninit`'s debug implementation
23+
// NB: there is no `.pad_fmt` so we can't use a simpler `format_args!("Padding<{..}>").
24+
let full_name = core::any::type_name::<Self>();
25+
let prefix_len = full_name.find("Padding").unwrap();
26+
f.pad(&full_name[prefix_len..])
27+
}
28+
}
29+
2030
/// The default repr type used for C style enums in Rust.
2131
#[cfg(target_env = "msvc")]
2232
#[allow(unused)]

0 commit comments

Comments
 (0)