๐Ÿ“ฆ ryanavella / struct-pad

Padding types for Rust, to enable memory layout optimizations

โ˜… 4 stars โ‘‚ 0 forks ๐Ÿ‘ 4 watching โš–๏ธ The Unlicense
paddingpadding-typesrust
๐Ÿ“ฅ Clone https://github.com/ryanavella/struct-pad.git
HTTPS git clone https://github.com/ryanavella/struct-pad.git
SSH git clone git@github.com:ryanavella/struct-pad.git
CLI gh repo clone ryanavella/struct-pad
Ryan Avella Ryan Avella Never mind the upper_case_acronyms lint was not a false positive, I confused it with the associated trait const. 4ee8922 2 years ago ๐Ÿ“ History
๐Ÿ“‚ master View all commits โ†’
๐Ÿ“ src
๐Ÿ“„ .gitignore
๐Ÿ“„ Cargo.toml
๐Ÿ“„ LICENSE-MIT
๐Ÿ“„ README.md
๐Ÿ“„ UNLICENSE
๐Ÿ“„ README.md

struct-pad

Padding types to enable memory layout optimizations.

License: MIT License: Unlicense crates.io docs.rs

Example

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,
        }
    }
}