11 releases (6 breaking)

new 0.6.0 Apr 29, 2021
0.4.0 Feb 19, 2021
0.2.1 Dec 12, 2020
0.2.0 Nov 19, 2020

#481 in Rust patterns

Download history 20/week @ 2021-01-08 31/week @ 2021-01-15 17/week @ 2021-01-22 26/week @ 2021-01-29 15/week @ 2021-02-05 49/week @ 2021-02-12 52/week @ 2021-02-19 19/week @ 2021-02-26 27/week @ 2021-03-05 113/week @ 2021-03-12 128/week @ 2021-03-19 94/week @ 2021-03-26 134/week @ 2021-04-02 210/week @ 2021-04-09 225/week @ 2021-04-16 428/week @ 2021-04-23

506 downloads per month
Used in 4 crates (via rkyv)

MIT license

97KB
2K SLoC

rkyv   Discord Latest Version License requires: rustc 1.47+

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

~345–770KB
~19K SLoC