@@ -10,14 +10,7 @@ that which is produced directly by `pythonize`.
10
10
This crate converts Rust types which implement the [ Serde] serialization
11
11
traits into Python objects using the [ PyO3] library.
12
12
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 ` .
21
14
22
15
</div >
23
16
@@ -28,30 +21,29 @@ PyO3 0.21 has introduced a significant new API, termed the "Bound" API after the
28
21
29
22
``` rust
30
23
use serde :: {Serialize , Deserialize };
31
- use pyo3 :: Python ;
32
- use pythonize :: {depythonize_bound , pythonize};
24
+ use pyo3 :: prelude :: * ;
25
+ use pythonize :: {depythonize , pythonize};
33
26
34
27
#[derive(Debug , Serialize , Deserialize , PartialEq )]
35
28
struct Sample {
36
29
foo : String ,
37
30
bar : Option <usize >
38
31
}
39
32
40
- let gil = Python :: acquire_gil ();
41
- let py = gil . python ();
42
-
43
33
let sample = Sample {
44
34
foo : " Foo" . to_string (),
45
35
bar : None
46
36
};
47
37
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 ();
50
41
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 ()));
52
43
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 ();
55
46
56
- assert_eq! (new_sample , sample );
47
+ assert_eq! (new_sample , sample );
48
+ })
57
49
```
0 commit comments