GithubHelp home page GithubHelp logo

rkyv's Introduction

rkyv โ€ƒ 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_value,
    de::deserializers::AllocDeserializer,
    ser::{
        serializers::WriteSerializer,
        Serializer,
    },
    Archive,
    Serialize,
    Deserialize,
};

#[derive(Archive, Deserialize, Serialize, Debug, PartialEq)]
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]),
    };

    let mut serializer = WriteSerializer::new(Vec::new());
    let pos = serializer.serialize_value(&value).expect("failed to serialize value");
    let buf = serializer.into_inner();

    let archived = unsafe { archived_value::<Test>(buf.as_ref(), pos) };
    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);
}

rkyv's People

Contributors

djkoloski avatar cgbur avatar pickfire avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.