How can I register a py class method into rust as a callback func and delay exec it when event comes? #3011
-
I know that pyo3 colud use call_method0 and call_method1 to call a py function. But if I dont want exec it instantly and want to register the func as callback. How to do that? |
Beta Was this translation helpful? Give feedback.
Answered by
adamreichold
Mar 5, 2023
Replies: 1 comment 2 replies
-
Get a handle on the method itself using |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
sun-rs
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Get a handle on the method itself using
let method: Py<PyAny> = object.getattr("method-name")?.into();
whereobject
is a&PyCell<MyRustClass>
. You can storemethod
where you want and when the time comes call it usingmethod.call1(py, (...))?;
.