#c-compatible #layout #stable #data #struct #enforcing #memory-layout

macro c_struct_layout

A library for enforcing stable, C-compatible data layouts in Rust

4 releases

0.1.3 Nov 21, 2024
0.1.2 Nov 21, 2024
0.1.1 Nov 6, 2024
0.1.0 Nov 6, 2024

#577 in Procedural macros

Download history 238/week @ 2024-11-05 4/week @ 2024-11-12 279/week @ 2024-11-19 12/week @ 2024-11-26

297 downloads per month

MIT license

4KB

c_struct_layout

A library for enforcing stable, C-compatible data layouts in Rust.

Features

  • Ensure consistent, C-compatible memory layouts for structs using #[repr(C)].
  • Provides a check_layout method to verify the layout at runtime (basic implementation).

Installation

To use c_struct_layout, add the following to your Cargo.toml:

[dependencies]
c_struct_layout = "0.1.0"

Usage

use c_struct_layout::CStructLayout;

#[derive(CStructLayout)]
#[repr(C)]
struct MyData {
    x: u32,
    y: f64,
}

fn main() {
    MyData::check_layout();
}

The check_layout method is a placeholder for verifying struct layouts. You can expand it with more detailed checks if needed.

License

This project is licensed under the MIT License

Author

bensatlantik

Dependencies

~1.5MB
~37K SLoC