devela::_dep::pyo3::marshal

Function dumps

pub fn dumps<'py>(
    object: &Bound<'py, PyAny>,
    version: i32,
) -> Result<Bound<'py, PyBytes>, PyErr> 
Available on crate features dep_pyo3 and std only.
Expand description

Serialize an object to bytes using the Python built-in marshal module.

The built-in marshalling only supports a limited range of objects. The exact types supported depend on the version argument. The VERSION constant holds the highest version currently supported.

See the Python documentation for more details.

§Examples

let dict = PyDict::new(py);
dict.set_item("aap", "noot").unwrap();
dict.set_item("mies", "wim").unwrap();
dict.set_item("zus", "jet").unwrap();

let bytes = marshal::dumps(&dict, marshal::VERSION);