Skip to content

Commit 8f76041

Browse files
authored
Merge pull request #74 from davidhewitt/update-readme
update `README.md` for newer APIs
2 parents 33451dc + 2b386e5 commit 8f76041

File tree

2 files changed

+13
-57
lines changed

2 files changed

+13
-57
lines changed

README.md

+11-19
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,7 @@ that which is produced directly by `pythonize`.
1010
This crate converts Rust types which implement the [Serde] serialization
1111
traits into Python objects using the [PyO3] library.
1212

13-
Pythonize has two public APIs: `pythonize` and `depythonize_bound`.
14-
15-
16-
<div class="warning">
17-
18-
⚠️ Warning: API update in progress 🛠️
19-
20-
PyO3 0.21 has introduced a significant new API, termed the "Bound" API after the new smart pointer `Bound<T>`, and pythonize is doing the same.
13+
Pythonize has two main public APIs: `pythonize` and `depythonize`.
2114

2215
</div>
2316

@@ -28,30 +21,29 @@ PyO3 0.21 has introduced a significant new API, termed the "Bound" API after the
2821

2922
```rust
3023
use serde::{Serialize, Deserialize};
31-
use pyo3::Python;
32-
use pythonize::{depythonize_bound, pythonize};
24+
use pyo3::prelude::*;
25+
use pythonize::{depythonize, pythonize};
3326

3427
#[derive(Debug, Serialize, Deserialize, PartialEq)]
3528
struct Sample {
3629
foo: String,
3730
bar: Option<usize>
3831
}
3932

40-
let gil = Python::acquire_gil();
41-
let py = gil.python();
42-
4333
let sample = Sample {
4434
foo: "Foo".to_string(),
4535
bar: None
4636
};
4737

48-
// Rust -> Python
49-
let obj = pythonize(py, &sample).unwrap();
38+
Python::with_gil(|py| {
39+
// Rust -> Python
40+
let obj = pythonize(py, &sample).unwrap();
5041

51-
assert_eq!("{'foo': 'Foo', 'bar': None}", &format!("{}", obj.as_ref(py).repr().unwrap()));
42+
assert_eq!("{'foo': 'Foo', 'bar': None}", &format!("{}", obj.repr().unwrap()));
5243

53-
// Python -> Rust
54-
let new_sample: Sample = depythonize_bound(obj.into_bound(py)).unwrap();
44+
// Python -> Rust
45+
let new_sample: Sample = depythonize(&obj).unwrap();
5546

56-
assert_eq!(new_sample, sample);
47+
assert_eq!(new_sample, sample);
48+
})
5749
```

src/lib.rs

+2-38
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,5 @@
1-
//! This crate converts Rust types which implement the [Serde] serialization
2-
//! traits into Python objects using the [PyO3] library.
3-
//!
4-
//! Pythonize has two public APIs: `pythonize` and `depythonize`.
5-
//!
6-
//! [Serde]: https://github.com/serde-rs/serde
7-
//! [PyO3]: https://github.com/PyO3/pyo3
8-
//!
9-
//! # Examples
10-
//! ```
11-
//! use serde::{Serialize, Deserialize};
12-
//! use pyo3::{types::PyAnyMethods, Python};
13-
//! use pythonize::{depythonize, pythonize};
14-
//!
15-
//! #[derive(Debug, Serialize, Deserialize, PartialEq)]
16-
//! struct Sample {
17-
//! foo: String,
18-
//! bar: Option<usize>
19-
//! }
20-
//!
21-
//! Python::with_gil(|py| {
22-
//! let sample = Sample {
23-
//! foo: "Foo".to_string(),
24-
//! bar: None
25-
//! };
26-
//!
27-
//! // Rust -> Python
28-
//! let obj = pythonize(py, &sample).unwrap();
29-
//!
30-
//! assert_eq!("{'foo': 'Foo', 'bar': None}", &format!("{}", obj.repr().unwrap()));
31-
//!
32-
//! // Python -> Rust
33-
//! let new_sample: Sample = depythonize(&obj).unwrap();
34-
//!
35-
//! assert_eq!(new_sample, sample);
36-
//! });
37-
//!
38-
//! ```
1+
#![doc = include_str!("../README.md")]
2+
393
mod de;
404
mod error;
415
mod ser;

0 commit comments

Comments
 (0)