Skip to content

Commit bbafd45

Browse files
mbyxtgross35
authored andcommitted
libc: add padding struct
1 parent c0071cc commit bbafd45

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-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: 8 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,14 +74,20 @@ 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;
7882
#[allow(unused_imports)]
83+
pub(crate) use ::core::prelude::v1::derive;
84+
#[allow(unused_imports)]
7985
pub(crate) use ::core::{fmt, hash, iter, mem};
8086
#[allow(unused_imports)]
8187
pub(crate) use mem::{align_of, align_of_val, size_of, size_of_val};
8288

89+
#[allow(unused_imports)]
90+
pub(crate) use crate::types::Padding;
8391
// Commonly used types defined in this crate
8492
#[allow(unused_imports)]
8593
pub(crate) use crate::{

src/types.rs

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

0 commit comments

Comments
 (0)