Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/rkyvPublic

Zero-copy deserialization framework for Rust

License

NotificationsYou must be signed in to change notification settings

rkyv/rkyv

Repository files navigation

rkyv

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

Discordcrates.iodocs.rsMIT license

Resources

Learning Materials

  • Therkyv book covers the motivation, architecture, and majorfeatures of rkyv
  • Therkyv discord is a great place to get help with specific issues and meetother people using rkyv

Documentation

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

Benchmarks

  • Therust serialization benchmark is ashootout style benchmark comparing many rust serialization solutions. It includes specialbenchmarks 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),)]structTest{int:u8,string:String,option:Option<Vec<i32>>,}fnmain(){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 calllet _bytes = rkyv::to_bytes::<Error>(&value).unwrap();// Or you can customize your serialization for better performance or control// over resource usageuse rkyv::{api::high::to_bytes_with_alloc, ser::allocator::Arena};letmut arena =Arena::new();let bytes =to_bytes_with_alloc::<_,Error>(&value, arena.acquire()).unwrap();// You can use the safe API for fast zero-copy deserializationlet archived = rkyv::access::<ArchivedTest,Error>(&bytes[..]).unwrap();assert_eq!(archived,&value);// Or you can use the unsafe API for maximum performancelet archived =unsafe{ rkyv::access_unchecked::<ArchivedTest>(&bytes[..])};assert_eq!(archived,&value);// And you can always deserialize back to the original typelet deserialized =deserialize::<Test,Error>(archived).unwrap();assert_eq!(deserialized, value);}

Note: the safe API requires thebytecheck feature (enabled by default)Read more aboutavailable features.

Thanks

Thanks to all the sponsors that keep development sustainable. Special thanks to the following sponsors for going above and beyond supporting rkyv:

Bronze Sponsors

Climatiq

Climatiq provides an embedded carbon intelligence solution that enables developers to automate GHG emission calculations based on verified scientific models. Its suite of products includes the largest dataset of emission factors, and intelligent APIs that integrate with any software platform for real time monitoring of greenhouse gas emissions.

About

Zero-copy deserialization framework for Rust

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp