1 个稳定版本

1.0.1 2021 年 12 月 5 日

#250 in FFI

BSD-2-Clause

7KB

示例

成功(实际大小与预期相符)

use pakr_assert_size::*;

#[repr(C, packed)]
#[assert_size(16)]
struct A {
    field1: u64,
    field2: u64,
}

#[assert_size(24)]
#[repr(C, packed)]
struct B {
    field1: u64,
    field2: u64,
    field3: u64,
}

失败(实际大小为 24 字节,预期为 32 字节)

use pakr_assert_size::*;

#[assert_size(32)]
#[repr(C, packed)]
struct C {
    field1: u64,
    field2: u64,
    field3: u64,
}

示例 assert_size_fits

成功(实际大小适合预期大小)

use pakr_assert_size::*;

// Exact match
#[repr(C, packed)]
#[assert_size_fits(16)]
struct A {
    field1: u64,
    field2: u64,
}

// Fits in match
#[assert_size_fits(32)]
#[repr(C, packed)]
struct B {
    field1: u64,
    field2: u64,
    field3: u64,
}

失败(实际大小为 24 字节,超过最大值 16 字节)

use pakr_assert_size::*;

#[assert_size_fits(16)]
#[repr(C, packed)]
struct C {
    field1: u64,
    field2: u64,
    field3: u64,
}

依赖项

~1.5MB
~35K SLoC