13 releases (5 breaking)

0.5.1 Apr 7, 2021
0.4.3 Mar 23, 2021
0.2.1 Dec 12, 2020
0.2.0 Nov 19, 2020

#119 in Encoding

Download history 4/week @ 2020-12-24 10/week @ 2020-12-31 12/week @ 2021-01-07 38/week @ 2021-01-14 18/week @ 2021-01-21 25/week @ 2021-01-28 18/week @ 2021-02-04 41/week @ 2021-02-11 57/week @ 2021-02-18 22/week @ 2021-02-25 16/week @ 2021-03-04 141/week @ 2021-03-11 156/week @ 2021-03-18 143/week @ 2021-03-25 125/week @ 2021-04-01 208/week @ 2021-04-08

265 downloads per month
Used in 3 crates

MIT license

225KB
4.5K SLoC

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


API Documentation

Book

  • The rkyv book covers the motivation and architecture of rkyv

Sister Crates:

  • bytecheck, which rkyv uses for validation
  • ptr_meta, which rkyv uses for pointer manipulation

rkyv in action

use rkyv::{
    archived_root,
    de::deserializers::AllocDeserializer,
    ser::{serializers::AlignedSerializer, Serializer},
    AlignedVec, Archive, Deserialize, 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 = AlignedSerializer::new(AlignedVec::new());
serializer
    .serialize_value(&value)
    .expect("failed to serialize value");
let buf = serializer.into_inner();

let archived = unsafe { archived_root::<Test>(buf.as_ref()) };
assert_eq!(archived.int, value.int);
assert_eq!(archived.string, value.string);
assert_eq!(archived.option, value.option);

let mut deserializer = AllocDeserializer;
let deserialized = archived
    .deserialize(&mut deserializer)
    .expect("failed to deserialize value");
assert_eq!(deserialized, value);

Dependencies

~0.4–0.8MB
~20K SLoC