Skip to content

Commit c29579f

Browse files
authored
Merge pull request #61 from sxlijin/main
docs: update readme example of depythonize
2 parents caa0d43 + f56a979 commit c29579f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@ 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`.
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.
21+
22+
</div>
1423

1524
[Serde]: https://github.com/serde-rs/serde
1625
[PyO3]: https://github.com/PyO3/pyo3
@@ -20,7 +29,7 @@ Pythonize has two public APIs: `pythonize` and `depythonize`.
2029
```rust
2130
use serde::{Serialize, Deserialize};
2231
use pyo3::Python;
23-
use pythonize::{depythonize, pythonize};
32+
use pythonize::{depythonize_bound, pythonize};
2433

2534
#[derive(Debug, Serialize, Deserialize, PartialEq)]
2635
struct Sample {
@@ -37,12 +46,12 @@ let sample = Sample {
3746
};
3847

3948
// Rust -> Python
40-
let obj = pythonize(py, &sample).unwrap();
49+
let obj = pythonize(py, &sample).unwrap();
4150

4251
assert_eq!("{'foo': 'Foo', 'bar': None}", &format!("{}", obj.as_ref(py).repr().unwrap()));
4352

4453
// Python -> Rust
45-
let new_sample: Sample = depythonize(obj.as_ref(py)).unwrap();
54+
let new_sample: Sample = depythonize_bound(obj.into_bound(py)).unwrap();
4655

4756
assert_eq!(new_sample, sample);
4857
```

0 commit comments

Comments
 (0)