https://github.com/ryanavella/struct-pad
Padding types for Rust, to enable memory layout optimizations
https://github.com/ryanavella/struct-pad
padding padding-types rust
Last synced: 4 months ago
JSON representation
Padding types for Rust, to enable memory layout optimizations
- Host: GitHub
- URL: https://github.com/ryanavella/struct-pad
- Owner: ryanavella
- License: unlicense
- Created: 2020-09-01T03:32:40.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-09-03T01:04:45.000Z (over 2 years ago)
- Last Synced: 2025-03-23T23:15:23.088Z (10 months ago)
- Topics: padding, padding-types, rust
- Language: Rust
- Homepage:
- Size: 6.84 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
# struct-pad
Padding types to enable memory layout optimizations.
[](https://github.com/ryanavella/struct-pad/blob/master/LICENSE-MIT) [](https://github.com/ryanavella/struct-pad/blob/master/UNLICENSE) [](https://crates.io/crates/struct-pad) [](https://docs.rs/struct-pad)
## Example
```rust
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,
}
}
}
```