Macro rkyv::project_struct [−][src]
macro_rules! project_struct { ($struct:ident: $ty:path => $field:tt) => { ... }; ($struct:ident: $struct_ty:path => $field:tt: $field_ty:path) => { ... }; }
Expand description
Maps a mutable MaybeUninit
struct reference to a mutable MaybeUninit
field reference.
This is primarily used to succintly resolve the fields of structs into the output for
resolve()
.
Example
use rkyv::project_struct; use core::mem::MaybeUninit; struct Test { a: i32, b: u8, } let result = unsafe { let mut result = MaybeUninit::<Test>::uninit(); let out = &mut result; project_struct!(out: Test => a: i32).as_mut_ptr().write(42); project_struct!(out: Test => b: u8).as_mut_ptr().write(10); result.assume_init() }; assert_eq!(result.a, 42); assert_eq!(result.b, 10);