Convert Rust enum with many types to PyAny #2652
-
I want to convert an enum we have, which is decorated with Serialize, Deserialize. The enum contains many types, some are structs, others are String or numeric types (there are over 20 of them). I tried Any advice on how to do this would be much appreciated. Great library by the way, overall pyo3 has been very easy to use. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Having the exact code written down here would be helpful to better diagnose the issue, but the way to go from Generally speaking, |
Beta Was this translation helpful? Give feedback.
Having the exact code written down here would be helpful to better diagnose the issue, but the way to go from
Py<PyAny>
to&'py PyAny
is via theas_ref
method, but this will only work given a GIL tokenPython<'py>
.Generally speaking,
PyAny
is not used as a value, but either as a reference-counted pointer into the Python heapPy<PyAny>
or as a reference bound to the lifetime of the GIL being taken&'py PyAny
, c.f. the memory section of the guide. So I think the underlying issue here is understanding why you need aPyAny
value in the first place.