| Crates.io | unsafe-tools-mimic |
| lib.rs | unsafe-tools-mimic |
| version | 0.1.2 |
| created_at | 2025-11-06 15:21:39.811719+00 |
| updated_at | 2025-11-12 10:49:03.037843+00 |
| description | Size and alignment matched opaque types |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1919798 |
| size | 232,470 |
mimicMimic generates "type-erased" struct definitions of equal size and equal alignment. This is useful in FFI scenarios where you don't want to or cannot communicate the exact layout and type of fields to the other language, but still want to communicate it's size and alignment e.g. to be able to stack-allocate the type.
use unsafe_tools_mimic::impl_mimic;
#[derive(Clone)]
pub struct Foo {
a: u64,
}
impl_mimic!(Foo);
let ty = Foo { a: 42 };
let mimic = ty.clone().into_mimic();
assert_eq!(size_of_val(&ty), size_of_val(&mimic));
assert_eq!(align_of_val(&ty), align_of_val(&mimic));