Skip to content

Commit 14167c4

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

File tree

3 files changed

+26
-1
lines changed

3 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/macros.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ macro_rules! cfg_if {
6464
/// Create an internal crate prelude with `core` reexports and common types.
6565
macro_rules! prelude {
6666
() => {
67+
mod types;
68+
6769
/// Frequently-used types that are available on all platforms
6870
///
6971
/// We need to reexport the core types so this works with `rust-dep-of-std`.
@@ -72,6 +74,8 @@ macro_rules! prelude {
7274
#[allow(unused_imports)]
7375
pub(crate) use ::core::clone::Clone;
7476
#[allow(unused_imports)]
77+
pub(crate) use ::core::default::Default;
78+
#[allow(unused_imports)]
7579
pub(crate) use ::core::marker::{Copy, Send, Sync};
7680
#[allow(unused_imports)]
7781
pub(crate) use ::core::option::Option;
@@ -80,6 +84,8 @@ macro_rules! prelude {
8084
#[allow(unused_imports)]
8185
pub(crate) use mem::{align_of, align_of_val, size_of, size_of_val};
8286

87+
#[allow(unused_imports)]
88+
pub(crate) use crate::types::Padding;
8389
// Commonly used types defined in this crate
8490
#[allow(unused_imports)]
8591
pub(crate) use crate::{

src/types.rs

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

0 commit comments

Comments
 (0)