serde-pickle

Crates.ioserde-pickle
lib.rsserde-pickle
version1.2.0
sourcesrc
created_at2016-04-22 16:36:35.378188
updated_at2024-11-22 17:16:18.908068
descriptionA serde-based serialization library for Python's pickle format
homepage
repositoryhttps://github.com/birkenfeld/serde-pickle
max_upload_size
id4818
size602,567
maintainers (github:rust-bus:maintainers)

documentation

http://docs.rs/serde-pickle

README

Serde Pickle Serialization Library

Build Status Latest Version

Documentation

This crate is a Rust library for parsing and generating Python pickle streams. It is built upon Serde, a high performance generic serialization framework.

Installation

This crate works with Cargo and can be found on crates.io with a Cargo.toml like:

[dependencies]
serde = "1.0"
serde-pickle = "1.1"

Requirements

Minimum supported Rust version is 1.63.0.

Usage

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::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::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).

Commit count: 106

cargo fmt