Skip to content

Commit 8cdddd4

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

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ 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+
pub use types::*;
48+
4649
cfg_if! {
4750
if #[cfg(windows)] {
4851
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::Padding;
8992
}
9093
};
9194
}

src/types.rs

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

0 commit comments

Comments
 (0)