storing python class instance in a struct #4246
-
If I have a class like class PythonClass:
def some_method(self):
... Is there any way I can store an instance of this class in a pub trait PythonClassTrait {
fn some_method(self);
}
#[pyclass]
struct RustStruct {
attr: Py<dyn PythonClassTrait>
} ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Not as a |
Beta Was this translation helpful? Give feedback.
-
Ah, interesting, thanks a lot ❤️. Are there any plans to add type checking via traits (or is it even possible to do so)? Also, do you think it's worth mentioning this in the docs? Speaking of docs, I forgot to say this earlier, but thanks so much for your work! PyO3 is extremely well documented and easy to use :) |
Beta Was this translation helpful? Give feedback.
Not as a
dyn Trait
. At the moment you should storePy<PyAny>
and go through functions like.call_method("some_method", args, kwargs)
.