77
88use std:: { collections:: HashMap , sync:: Arc } ;
99
10- use pyo3:: { prelude:: * , types :: PyDict } ;
11- use pyo3_asyncio :: tokio:: future_into_py_with_locals;
10+ use pyo3:: prelude:: * ;
11+ use pyo3_async_runtimes :: tokio:: future_into_py_with_locals;
1212use reccaster:: { Record , Reccaster } ;
1313use tokio:: sync:: Mutex ;
1414
@@ -39,23 +39,18 @@ impl PyRecord {
3939 }
4040
4141 #[ getter]
42- fn properties < ' py > ( & self , py : Python < ' py > ) -> PyResult < & ' py PyDict > {
43- let properties = PyDict :: new ( py) ;
44- for ( key, value) in & self . 0 . properties {
45- properties. set_item ( key, value) ?;
46- }
47- Ok ( properties)
42+ fn properties ( & self ) -> PyResult < HashMap < String , String > > {
43+ Ok ( self . 0 . properties . clone ( ) )
4844 }
4945
5046}
5147
52- impl < ' source > FromPyObject < ' source > for PyRecord {
53- fn extract ( ob : & ' source PyAny ) -> PyResult < Self > {
48+ impl FromPyObject < ' _ > for PyRecord {
49+ fn extract_bound ( ob : & Bound < ' _ , PyAny > ) -> PyResult < Self > {
5450 let name: String = ob. getattr ( "name" ) ?. extract ( ) . unwrap_or_else ( |_| "OPS no name !!!!!!!!!!!" . to_string ( ) ) ;
5551 let r#type: String = ob. getattr ( "type" ) ?. extract ( ) ?;
5652 let alias: Option < String > = ob. getattr ( "alias" ) ?. extract ( ) ?;
5753 let properties: HashMap < String , String > = ob. getattr ( "properties" ) ?. extract ( ) ?;
58-
5954 Ok ( PyRecord ( Record { name, r#type, alias, properties } ) )
6055 }
6156}
@@ -69,21 +64,20 @@ struct PyReccaster {
6964impl PyReccaster {
7065
7166 #[ staticmethod]
72- fn setup ( py : Python , records : Vec < PyRecord > , props : Option < HashMap < String , String > > ) -> PyResult < & PyAny > {
73- let locals = pyo3_asyncio :: tokio:: get_current_locals ( py) ?;
67+ fn setup ( py : Python , records : Vec < PyRecord > , props : Option < HashMap < String , String > > ) -> PyResult < Bound < ' _ , pyo3 :: PyAny > > {
68+ let locals = pyo3_async_runtimes :: tokio:: get_current_locals ( py) ?;
7469 let pvs = records. iter ( ) . map ( |record : & PyRecord | record. 0 . clone ( ) ) . collect :: < Vec < Record > > ( ) ;
75- future_into_py_with_locals ( py, locals. clone ( ) , async move {
70+ future_into_py_with_locals ( py, locals, async move {
7671 let recc = Reccaster :: new ( pvs, props) . await ;
7772 let pyrecc = PyReccaster { reccaster : Arc :: new ( Mutex :: new ( recc) ) } ;
78- Python :: with_gil ( |py | Ok ( pyrecc. into_py ( py ) ) )
73+ Python :: with_gil ( |_py | Ok ( pyrecc) )
7974 } )
8075 }
8176
82- fn run < ' p > ( & self , py : Python < ' p > ) -> PyResult < & ' p PyAny > {
77+ fn run < ' a > ( & self , py : Python < ' a > ) -> PyResult < Bound < ' a , PyAny > > {
8378 let recc_arc = self . reccaster . clone ( ) ;
84- let locals = pyo3_asyncio:: tokio:: get_current_locals ( py) ?;
85-
86- future_into_py_with_locals ( py, locals. clone ( ) , async move {
79+ let locals = pyo3_async_runtimes:: tokio:: get_current_locals ( py) ?;
80+ future_into_py_with_locals ( py, locals, async move {
8781 let mut recc = recc_arc. lock ( ) . await ;
8882 recc. run ( ) . await ;
8983 Ok ( ( ) )
@@ -92,7 +86,7 @@ impl PyReccaster {
9286}
9387
9488#[ pymodule]
95- fn pyreccaster ( _py : Python , m : & PyModule ) -> PyResult < ( ) > {
89+ fn pyreccaster ( _py : Python , m : & Bound < ' _ , PyModule > ) -> PyResult < ( ) > {
9690 m. add_class :: < PyReccaster > ( ) ?;
9791 m. add_class :: < PyRecord > ( ) ?;
9892 Ok ( ( ) )
0 commit comments