#alignment #struct #packing #padding #layout #proc-macro #graphics

alignment-exporter

提供用户定义结构体对齐信息的处理宏

1 个不稳定版本

0.1.3 2024年8月14日
0.1.2 2024年8月14日
0.1.1 2024年8月14日
0.1.0 2024年8月14日

#758数据结构

Download history 378/week @ 2024-08-10

每月378次下载

MIT 许可证

4KB

此crate为用户定义的结构体提供对齐信息,但随着时间的推移,此crate的功能范围已扩大,包括其他信息,例如结构体字段的类型名称。

use alignment_exporter::{Alignment, AlignmentExporter, export_alignment};

// `export_alignment` already annotates #[repr(C)] to the struct, so adding that yourself is not required. However, it is always better to include it in your code for the sake of explicitness.
#[export_alignment]
struct Example {
    a: u8,
    b: u32,
    c: u16
}

fn main() {
    let alignment = Example::get_alignment();
    assert_eq!(alignment, vec![
        Alignment { size: 1, offset: 0, ty_name: "u8" },
        Alignment { size: 4, offset: 1, ty_name: "u32" },
        Alignment { size: 2, offset: 8, ty_name: "u16" },
    ]);
}

依赖项

~275–730KB
~17K SLoC