You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
rend, which rkyv uses for endian-agnostic features
ptr_meta, which rkyv uses for pointer manipulation
Example
use rkyv::{deserialize, rancor::Error,Archive,Deserialize,Serialize};#[derive(Archive,Deserialize,Serialize,Debug,PartialEq)]#[rkyv(// This will generate a PartialEq impl between our unarchived// and archived types compare(PartialEq),// Derives can be passed through to the generated type: derive(Debug),)]structTest{int:u8,string:String,option:Option<Vec<i32>>,}fnmain(){let value = Test{int:42,string:"hello world".to_string(),option:Some(vec![1,2,3,4]),};// Serializing is as easy as a single function calllet _bytes = rkyv::to_bytes::<Error>(&value).unwrap();// Or you can customize your serialization for better performance or control// over resource usageuse rkyv::{api::high::to_bytes_with_alloc, ser::allocator::Arena};letmut arena = Arena::new();let bytes =
to_bytes_with_alloc::<_,Error>(&value, arena.acquire()).unwrap();// You can use the safe API for fast zero-copy deserializationlet archived = rkyv::access::<ArchivedTest,Error>(&bytes[..]).unwrap();assert_eq!(archived,&value);// Or you can use the unsafe API for maximum performancelet archived =
unsafe{ rkyv::access_unchecked::<ArchivedTest>(&bytes[..])};assert_eq!(archived,&value);// And you can always deserialize back to the original typelet deserialized = deserialize::<Test,Error>(archived).unwrap();assert_eq!(deserialized, value);}
Note: the safe API requires the bytecheck feature (enabled by default)Read more about available features.
Thanks
Thanks to all the sponsors that keep development sustainable.