Return multiple structs from Rust method back to Python #3567
-
This is a follow-up question from the https://github.com/roma-glushko/notifykit/ project. I'm mapping some events on the Rust side to different structs (e.g. CreateEvent, DeleteEvent, RenameEvent, etc.). I want those struct to get to Python world, so Python code could invoke some specific methods/attributes on them. I'm wondering how typing should look like on the Rust/PyO3 side to make this transpire 👀 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Do you want a common base class? Or do you just want four separate It's not clear to me what the question is. How you want your API to look is your choice. |
Beta Was this translation helpful? Give feedback.
Sorry for the slow reply. I think it's sufficient to just use
PyObject
as the return type from your function, and use e.g.create_event.into_py(py)
to convert the typed instances into them.