Skip to content

Commit e40f470

Browse files
3v1n0tgross35
authored andcommitted
types: Add Padding<T>::uninit()
It allows to uninitialize padding areas in const contextes.
1 parent d5a75f3 commit e40f470

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/types.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ impl<T: Copy> Default for Padding<T> {
2222
}
2323
}
2424

25+
impl<T: Copy> Padding<T> {
26+
/// Const constructor for uninitialized padding in const contexts.
27+
// FIXME: Change this into zeroed() and use MaybeUninit::zeroed()
28+
// when we depend on rustc 1.75.0.
29+
#[allow(unused)]
30+
pub(crate) const fn uninit() -> Self {
31+
// We can still safely use uninit here, since padding are is something
32+
// that can are not meant to be read or written anyways.
33+
Self(MaybeUninit::uninit())
34+
}
35+
}
36+
2537
impl<T: Copy> fmt::Debug for Padding<T> {
2638
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2739
// Taken frmo `MaybeUninit`'s debug implementation

0 commit comments

Comments
 (0)