Crate serde_pickle [] [src]

Serialization and deserialization for Python's pickle format

Pickle format

Please see the Python docs for details on the Pickle format.

This crate supports all Pickle protocols (0 to 4) when reading, and writing protocol 2 (compatible with Python 2 and 3), or protocol 3 (compatible with Python 3 only).

Supported types

Pickle is very powerful. It is capable of serializing pretty arbitrary graphs of Python objects, with most custom classes being serialized out of the box. Currently, this crate only supports Python's built-in types that map easily to Rust constructs. There are:

  • None
  • Boolean (Rust bool)
  • Integers (Rust i64 or bigints from num)
  • Floats (Rust f64)
  • Strings (Rust Vec<u8>)
  • Unicode strings (Rust String)
  • Lists and tuples (Rust Vec<Value>)
  • Sets and frozensets (Rust HashSet<Value>)
  • Dictionaries (Rust HashMap<Value, Value>)

Exported API

The library exports generic serde (de)serializing functions to_* and from_*. It also exports functions that produce or take only the specific Value struct exposed by this library, which supports all built-in Python types (notably, long integers and sets, which serde's generic types don't handle). These functions, called value_from_* and value_to_*, will correctly (un)pickle these types.

Reexports

pub use self::ser::{Serializer, to_writer, to_vec, value_to_writer, value_to_vec};
pub use self::de::{Deserializer, from_reader, from_slice, from_iter, value_from_reader, value_from_slice, value_from_iter};
pub use self::value::{Value, HashableValue};
pub use self::error::{Error, ErrorCode, Result};

Modules

de
error

Error objects and codes

ser

Pickle serialization

value

Python values, and serialization instances for them.

Functions

from_value

Deserialize a value::Value from any serde deserializable object.

to_value

Serialize any serde serializable object into a value::Value.