forked from davidhewitt/pythonize
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
52 lines (51 loc) · 1.39 KB
/
lib.rs
File metadata and controls
52 lines (51 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//! This crate converts Rust types which implement the [Serde] serialization
//! traits into Python objects using the [PyO3] library.
//!
//! Pythonize has two public APIs: `pythonize` and `depythonize`.
//!
//! [Serde]: https://github.com/serde-rs/serde
//! [PyO3]: https://github.com/PyO3/pyo3
//!
//! # Examples
//! ```
//! use serde::{Serialize, Deserialize};
//! use pyo3::Python;
//! use pythonize::{depythonize, pythonize};
//!
//! #[derive(Debug, Serialize, Deserialize, PartialEq)]
//! struct Sample {
//! foo: String,
//! bar: Option<usize>
//! }
//!
//! # pyo3::prepare_freethreaded_python();
//!
//! Python::with_gil(|py| {
//! let sample = Sample {
//! foo: "Foo".to_string(),
//! bar: None
//! };
//!
//! // Rust -> Python
//! let obj = pythonize(py, &sample).unwrap();
//!
//! assert_eq!("{'foo': 'Foo', 'bar': None}", &format!("{}", obj.as_ref(py).repr().unwrap()));
//!
//! // Python -> Rust
//! let new_sample: Sample = depythonize(obj.as_ref(py)).unwrap();
//!
//! assert_eq!(new_sample, sample);
//! });
//!
//! ```
mod de;
mod error;
mod ser;
#[allow(deprecated)]
pub use crate::de::depythonize;
pub use crate::de::{depythonize_bound, Depythonizer};
pub use crate::error::{PythonizeError, Result};
pub use crate::ser::{
pythonize, pythonize_custom, PythonizeDefault, PythonizeDictType, PythonizeListType,
PythonizeTypes, Pythonizer,
};