Crates.io | struct-pad |
lib.rs | struct-pad |
version | 0.2.0 |
source | src |
created_at | 2020-09-01 03:42:25.598101 |
updated_at | 2020-09-03 03:02:02.488148 |
description | Padding types to enable memory layout optimizations. |
homepage | https://github.com/ryanavella/struct-pad |
repository | https://github.com/ryanavella/struct-pad |
max_upload_size | |
id | 283294 |
size | 15,706 |
Padding types to enable memory layout optimizations.
use struct_pad::{Pad, PadU0, PadU8, PadU16, PadU32};
struct Example {
field1: u64,
field2: u8,
// Padding fields
pad1: PadU8,
#[cfg(target_pointer_width = "16")]
pad2: PadU0,
#[cfg(not(target_pointer_width = "16"))]
pad2: PadU16,
#[cfg(target_pointer_width = "64")]
pad3: PadU32,
#[cfg(not(target_pointer_width = "64"))]
pad3: PadU0,
}
impl Example {
const fn new(field1: u64, field2: u8) -> Self {
Self {
field1,
field2,
pad1: Pad::VALUE,
pad2: Pad::VALUE,
pad3: Pad::VALUE,
}
}
}