#size #padding #calculate #derive #procedural #proc-macro #size-of-no-padding

macro size-of-no-padding-derive

A procedural macro to calculate the size of a type without padding

1 unstable release

new 0.1.5 Mar 23, 2025

#30 in #calculate

Download history 89/week @ 2025-03-18

89 downloads per month
Used in size-of-no-padding

MIT/Apache

7KB
122 lines

Size Of No Padding

This crate provides the derive proc macro SizeOfNoPadding, it will generate size_of_no_padding() method for your struct or union which can calcuate the size of struct or union without padding even if it is not marked as #[repr(packed)].

Example

use size_of_no_padding::SizeOfNoPadding;

#[derive(SizeOfNoPadding)]
struct Abc {
    a: u8,
    b: u32,
    c: u8,
}

fn main() {
    assert_eq!(8, std::mem::size_of::<Abc>());
    assert_eq!(6, Abc::size_of_no_padding());
}

License

Licensed under either of

at your option.

Dependencies

~215–650KB
~16K SLoC