-
Notifications
You must be signed in to change notification settings - Fork 791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to wrap a struct with lifetime parameter? #502
Comments
It's not allowed now since it's really difficult to handle the lifetime from Python side. |
For illustration, the issue is that as a pyclass, the object has to be able to be passed into Python code. For that, it has to be put onto the Python heap, at which point the lifetime is out of control of Rust and the borrow checker. It can be kept alive potentially indefinitely by Python references. |
That said, the error could be a lot clearer :) |
Agreed 👍 |
@birkenfeld I thought so already... |
PR with better error message has been merged |
Is there a workaround for the fundamental issue here? If I need to wrap a struct from a pure-Rust library that uses lifetimes, how do I do that, short of rewriting the pure-Rust library to work within PyO3 limitations? Is there some clever hack/indirection to get around this limitation? |
You could only unsafely |
🐛 Bug Reports
This is different to issue 246.
🌍 Environment
rustc --version
): rustc 1.34.0-nightly (e1c6d0057 2019-02-22)version = "0.x.y"
withgit = "https://github.com/PyO3/pyo3")?
version: 0.7.0💥 Reproducing
When using a struct with lifetime as follow:
results in the compiler error:
Using dependency:
The text was updated successfully, but these errors were encountered: