rkyv: Zero-Copy Rust Structs
use rkyv::{Archive, Serialize, Deserialize};
#[derive(Archive, Serialize, Deserialize)]
struct KvPair {
key: String,
value: Vec<u8>,
}
let bytes = rkyv::to_bytes::<KvPair, 256>(&kv).unwrap();
let archived = unsafe { rkyv::archived_root::<KvPair>(&bytes) };
println!("{}", archived.key);
rkyv works by writing the struct in a layout that matches memory layout — the "archived" struct is usable directly from the byte buffer.