rkyv_derive

Zero-copy deserialization framework for Rust

Latest version: 0.8.16 registry icon
Maintenance score
100
Safety score
100
Popularity score
93
Check your open source dependency risks. Get immediate insight about security, stability and licensing risks.
Security
  Vulnerabilities
Version Suggest Low Medium High Critical
0.8.16 0 0 0 0 0
0.8.15 0 0 0 0 0
0.8.14 0 0 0 0 0
0.8.13 0 0 0 0 0
0.8.12 0 0 0 0 0
0.8.11 0 0 0 0 0
0.8.10 0 0 0 0 0
0.8.9 0 0 0 0 0
0.8.8 0 0 0 0 0
0.8.7 0 0 0 0 0
0.8.6 0 0 0 0 0
0.8.5 0 0 0 0 0
0.8.4 0 0 0 0 0
0.8.3 0 0 0 0 0
0.8.2 0 0 0 0 0
0.8.1 0 0 0 0 0
0.8.0 0 0 0 0 0
0.7.46 0 0 0 0 0
0.7.45 0 0 0 0 0
0.7.44 0 0 0 0 0
0.7.43 0 0 0 0 0
0.7.42 0 0 0 0 0
0.7.41 0 0 0 0 0
0.7.40 0 0 0 0 0
0.7.39 0 0 0 0 0
0.7.38 0 0 0 0 0
0.7.37 0 0 0 0 0
0.7.36 0 0 0 0 0
0.7.35 0 0 0 0 0
0.7.34 0 0 0 0 0
0.7.33 0 0 0 0 0
0.7.32 0 0 0 0 0
0.7.31 0 0 0 0 0
0.7.30 0 0 0 0 0
0.7.29 0 0 0 0 0
0.7.28 0 0 0 0 0
0.7.27 0 0 0 0 0
0.7.26 0 0 0 0 0
0.7.25 0 0 0 0 0
0.7.24 0 0 0 0 0
0.7.22 0 0 0 0 0
0.7.21 0 0 0 0 0
0.7.20 0 0 0 0 0
0.7.19 0 0 0 0 0
0.7.18 0 0 0 0 0
0.7.17 0 0 0 0 0
0.7.16 0 0 0 0 0
0.7.15 0 0 0 0 0
0.7.14 0 0 0 0 0
0.7.13 0 0 0 0 0
0.7.12 0 0 0 0 0
0.7.11 0 0 0 0 0
0.7.10 0 0 0 0 0
0.7.9 0 0 0 0 0
0.7.8 0 0 0 0 0
0.7.7 0 0 0 0 0
0.7.6 0 0 0 0 0
0.7.5 0 0 0 0 0
0.7.4 0 0 0 0 0
0.7.3 0 0 0 0 0
0.7.2 0 0 0 0 0
0.7.1 0 0 0 0 0
0.7.0 0 0 0 0 0
0.6.7 0 0 0 0 0
0.6.3 0 0 0 0 0
0.6.0 0 0 0 0 0
0.5.1 0 0 0 0 0
0.5.0 0 0 0 0 0
0.4.0 0 0 0 0 0
0.3.1 0 0 0 0 0
0.3.0 0 0 0 0 0
0.2.1 0 0 0 0 0
0.2.0 0 0 0 0 0
0.1.1 0 0 0 0 0
0.1.0 0 0 0 0 0
0.0.0 0 0 0 0 0

Stability
Latest release:

0.8.16 - This version is safe to use because it has no known security vulnerabilities at this time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform

Licensing

Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.

MIT   -   MIT License

Not a wildcard

Not proprietary

OSI Compliant



rkyv

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

Discord crates.io docs.rs MIT license

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

  • rkyv, the core library
  • rkyv_dyn, which adds trait object support to rkyv

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

  • rend, which rkyv uses for endian-agnostic features
  • bytecheck, which rkyv uses for validation
  • rancor, which rkyv uses for error handling
  • 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),
)]
struct Test {
    int: u8,
    string: String,
    option: Option<Vec<i32>>,
}

fn main() {
    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 call
    let _bytes = rkyv::to_bytes::<Error>(&value).unwrap();

    // Or you can customize your serialization for better performance or control
    // over resource usage
    use rkyv::{api::high::to_bytes_with_alloc, ser::allocator::Arena};

    let mut arena = Arena::new();
    let bytes =
        to_bytes_with_alloc::<_, Error>(&value, arena.acquire()).unwrap();

    // You can use the safe API for fast zero-copy deserialization
    let archived = rkyv::access::<ArchivedTest, Error>(&bytes[..]).unwrap();
    assert_eq!(archived, &value);

    // Or you can use the unsafe API for maximum performance
    let archived =
        unsafe { rkyv::access_unchecked::<ArchivedTest>(&bytes[..]) };
    assert_eq!(archived, &value);

    // And you can always deserialize back to the original type
    let 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.