rkyv (archive) is a zero-copy deserialization framework for Rust
Resources
Learning Materials
- The rkyv book covers the motivation, architecture, and major
features of rkyv
- The rkyv discord is a great place to get help with specific issues and meet
other people using rkyv
Documentation
Benchmarks
- The rust serialization benchmark is a
shootout style benchmark comparing many rust serialization solutions. It includes special
benchmarks for zero-copy serialization solutions like rkyv.
Sister Crates
- bytecheck, which rkyv uses for validation
- ptr_meta, which rkyv uses for pointer manipulation
- rend, which rkyv uses for endian-agnostic features
Example
```rust
use rkyv::{
archived_root,
ser::{serializers::AllocSerializer, Serializer},
Archive, Deserialize, Infallible, Serialize,
};
[derive(Archive, Deserialize, Serialize, Debug, PartialEq)]
struct Test {
int: u8,
string: String,
option: Option>,
}
let value = Test {
int: 42,
string: "hello world".to_string(),
option: Some(vec![1, 2, 3, 4]),
};
let mut serializer = AllocSerializer::<256>::default();
serializer.serializevalue(&value).unwrap();
let bytes = serializer.intoserializer().into_inner();
let archived = unsafe { archivedroot::(&bytes[..]) };
asserteq!(archived.int, value.int);
asserteq!(archived.string, value.string);
asserteq!(archived.option, value.option);
let deserialized: Test = archived.deserialize(&mut Infallible).unwrap()
assert_eq!(deserialized, value);
```