| Crates.io | memory-layout |
| lib.rs | memory-layout |
| version | 0.3.0 |
| created_at | 2023-04-26 07:24:07.17489+00 |
| updated_at | 2023-06-29 13:10:31.141708+00 |
| description | explicit struct layouts. |
| homepage | |
| repository | https://github.com/DottieDot/memory-layout-rs |
| max_upload_size | |
| id | 849116 |
| size | 4,277 |
memory-layout is a minimal no_std compatible crate that allows you to specify the memory layout of a struct, similarly to C#'s [StructLayout(LayoutKind.Explicit)].
https://docs.rs/memory-layout/
no_std compatible.use memory_layout::memory_layout;
#[memory_layout]
pub struct Example {
#[field_offset(0x00)]
a: i32,
#[field_offset(0x10)]
b: u64,
#[field_offset(0x20)]
c: f32
}
Will expand to:
pub struct Example {
#[doc(hidden)]
__pad0: [u8; 0usize],
a: i32,
#[doc(hidden)]
__pad1: [u8; 16usize - ::core::mem::size_of::<i32>()],
b: u64,
#[doc(hidden)]
__pad2: [u8; 8usize - ::core::mem::size_of::<u64>()],
c: f32
}
#[memory_layout] attribute has to be defined before any derive attributes.This project has a similar goal to this crate, replicating C#'s [StructLayout(LayoutKind.Explicit)]. The key difference is that struct_layout uses an internal array that can be accessed using methods like get_<field_name> and set_<field_name> while this crate aligns the fields themselves.