struct-pad 0.2.0

Padding types to enable memory layout optimizations.
Documentation
  • Coverage
  • 100%
    9 out of 9 items documented1 out of 7 items with examples
  • Size
  • Source code size: 15.33 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.61 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • ryanavella/struct-pad
    4 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ryanavella

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