15 releases (7 breaking)

new 0.7.4 Jul 22, 2021
0.7.0-pre.1 Jun 21, 2021
0.4.0 Feb 19, 2021
0.2.1 Dec 12, 2020
0.2.0 Nov 19, 2020
Download history 35/week @ 2021-04-03 19/week @ 2021-04-10 19/week @ 2021-04-17 18/week @ 2021-04-24 13/week @ 2021-05-01 4/week @ 2021-05-08 10/week @ 2021-05-15 1/week @ 2021-05-22 2/week @ 2021-05-29 11/week @ 2021-06-05 22/week @ 2021-06-12 22/week @ 2021-06-19 5/week @ 2021-06-26 50/week @ 2021-07-03 11/week @ 2021-07-10 39/week @ 2021-07-17

67 downloads per month
Used in 2 crates (via rkyv_typename)

MIT license

6KB
125 lines

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

~320–750KB
~19K SLoC