45 releases (7 breaking)

new 0.7.20 Oct 23, 2021
0.7.18 Sep 15, 2021
0.7.4 Jul 22, 2021
0.4.3 Mar 23, 2021
0.2.0 Nov 19, 2020

#24 in Encoding

Download history 2366/week @ 2021-07-03 3376/week @ 2021-07-10 4157/week @ 2021-07-17 2669/week @ 2021-07-24 2955/week @ 2021-07-31 4146/week @ 2021-08-07 4716/week @ 2021-08-14 3556/week @ 2021-08-21 4092/week @ 2021-08-28 4145/week @ 2021-09-04 5585/week @ 2021-09-11 7757/week @ 2021-09-18 9503/week @ 2021-09-25 8387/week @ 2021-10-02 8319/week @ 2021-10-09 9248/week @ 2021-10-16

24,912 downloads per month
Used in 44 crates (31 directly)

MIT license

655KB
14K SLoC

rkyv (archive) is a zero-copy deserialization framework for Rust

Discord

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

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<Vec<i32>>,
}

let value = Test {
    int: 42,
    string: "hello world".to_string(),
    option: Some(vec![1, 2, 3, 4]),
};

let mut serializer = AllocSerializer::<256>::default();
serializer.serialize_value(&value).unwrap();
let bytes = serializer.into_serializer().into_inner();

let archived = unsafe { archived_root::<Test>(&bytes[..]) };
assert_eq!(archived.int, value.int);
assert_eq!(archived.string, value.string);
assert_eq!(archived.option, value.option);

let deserialized: Test = archived.deserialize(&mut Infallible).unwrap()
assert_eq!(deserialized, value);

Dependencies

~0.4–1.1MB
~26K SLoC