Skip to content

Convert Rust enum with many types to PyAny #2652

Discussion options

You must be logged in to vote

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 the as_ref method, but this will only work given a GIL token Python<'py>.

Generally speaking, PyAny is not used as a value, but either as a reference-counted pointer into the Python heap Py<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 a PyAny value in the first place.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@cisaacson
Comment options

@adamreichold
Comment options

@cisaacson
Comment options

Answer selected by cisaacson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants