Crates.io | serde-pickle-rs |
lib.rs | serde-pickle-rs |
version | 1.0.2 |
source | src |
created_at | 2023-11-11 11:33:06.015829 |
updated_at | 2023-11-12 15:37:08.379736 |
description | A serde-based serialization library for Python's pickle format |
homepage | |
repository | https://github.com/spinorml/serde-pickle-rs |
max_upload_size | |
id | 1032006 |
size | 599,871 |
This crate is a Rust library for parsing and generating Python pickle streams, forked from serde-pickle. That crate has not been updated in a while, and does not support some parts of the pickle spec (e.g. PERSID), which is required to parse the Meta LlaMA models.
It is built upon Serde, a high performance generic serialization framework.
This crate works with Cargo and can be found on
crates.io with a Cargo.toml
like:
[dependencies]
serde = "1.0.192"
serde-pickle-rs = "1.0.1"
Minimum supported Rust version is 1.73.0.
As with other serde serialization implementations, this library provides toplevel functions for simple en/decoding of supported objects.
Example:
use std::collections::BTreeMap;
fn main() {
let mut map = BTreeMap::new();
map.insert("x".to_string(), 1.0);
map.insert("y".to_string(), 2.0);
// Serialize the map into a pickle stream.
// The second argument are serialization options.
let serialized = serde_pickle_rs::to_vec(&map, Default::default()).unwrap();
// Deserialize the pickle stream back into a map.
// Because we compare it to the original `map` below, Rust infers
// the type of `deserialized` and lets serde work its magic.
// The second argument are additional deserialization options.
let deserialized = serde_pickle_rs::from_slice(&serialized, Default::default()).unwrap();
assert_eq!(map, deserialized);
}
Serializing and deserializing structs and enums that implement the
serde-provided traits is supported, and works analogous to other crates
(using serde_derive
).