Repository navigation
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. |
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, |
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 PyAnyis via theas_refmethod, but this will only work given a GIL tokenPython<'py>.Generally speaking,
PyAnyis 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 aPyAnyvalue in the first place.