@@ -10,14 +10,7 @@ that which is produced directly by `pythonize`.
1010This crate converts Rust types which implement the [ Serde] serialization
1111traits 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
3023use 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 )]
3528struct Sample {
3629 foo : String ,
3730 bar : Option <usize >
3831}
3932
40- let gil = Python :: acquire_gil ();
41- let py = gil . python ();
42-
4333let 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```
0 commit comments