Skip to content

Commit 8dd85bd

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

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

libc-test/test/check_style.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use style::{Result, StyleChecker};
2020
const SKIP_PREFIXES: &[&str] = &[
2121
// Don't run the style checker on the reorganized portion of the crate while we figure
2222
// out what style we want.
23-
"new/",
23+
"new/", "types.rs",
2424
];
2525

2626
#[test]

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
@@ -80,6 +80,9 @@ macro_rules! prelude {
8080
#[allow(unused_imports)]
8181
pub(crate) use mem::{align_of, align_of_val, size_of, size_of_val};
8282

83+
#[allow(unused_imports)]
84+
pub(crate) use crate::types::Padding;
85+
8386
// Commonly used types defined in this crate
8487
#[allow(unused_imports)]
8588
pub(crate) use crate::{

src/types.rs

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

0 commit comments

Comments
 (0)