Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use crate::prelude::*;

/// A transparent wrapper over `MaybeUninit<T>` to represent uninitialized padding
/// while providing `Default`.
// This is restricted to `Copy` types since that's a loose indicator that zeros is actually
// a valid bitpattern. There is no technical reason this is required, though, so it could be
// lifted in the future if it becomes a problem.
#[allow(unused)]
#[repr(transparent)]
#[derive(Clone, Copy)]
Expand All @@ -17,6 +20,16 @@ impl<T: Copy> Default for Padding<T> {
}
}

impl<T: Copy> fmt::Debug for Padding<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Taken frmo `MaybeUninit`'s debug implementation
// NB: there is no `.pad_fmt` so we can't use a simpler `format_args!("Padding<{..}>").
let full_name = core::any::type_name::<Self>();
let prefix_len = full_name.find("Padding").unwrap();
f.pad(&full_name[prefix_len..])
}
}

/// The default repr type used for C style enums in Rust.
#[cfg(target_env = "msvc")]
#[allow(unused)]
Expand Down
Loading