Skip to content

Commit b20e865

Browse files
committed
libc: add padding struct
1 parent c0071cc commit b20e865

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub use core::ffi::c_void;
4343
#[allow(unused_imports)] // needed while the module is empty on some platforms
4444
pub use new::*;
4545

46+
mod types;
47+
4648
cfg_if! {
4749
if #[cfg(windows)] {
4850
mod primitives;

src/macros.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ macro_rules! prelude {
8686
c_char, c_double, c_float, c_int, c_long, c_longlong, c_short, c_uchar, c_uint,
8787
c_ulong, c_ulonglong, c_ushort, c_void, intptr_t, size_t, ssize_t, uintptr_t,
8888
};
89+
90+
#[allow(unused_imports)]
91+
pub(crate) use crate::types::Padding;
8992
}
9093
};
9194
}

src/types.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! Platform-agnostic support types.
2+
3+
use core::mem::MaybeUninit;
4+
5+
/// A transparent wrapper over `MaybeUninit<T>` to represent uninitialized padding
6+
/// while providing `Default`.
7+
#[allow(unused)]
8+
#[repr(transparent)]
9+
#[derive(Clone, Copy)]
10+
pub(crate) struct Padding<T: Copy>(MaybeUninit<T>);
11+
12+
impl<T: Copy> Default for Padding<T> {
13+
fn default() -> Self {
14+
Self(MaybeUninit::zeroed())
15+
}
16+
}

0 commit comments

Comments
 (0)