Hacker News new | ask | show | jobs
by vvanders 3103 days ago
In that case RefCell[1] is the right approach. I use it a ton with C callbacks where like you said you can't get the compiler to understand lifetimes. You get the added bonus of Rust validating the lifetime at runtime and catching any regressions.

In the rare case where the lifetime check is too expensive you're free to turn the types into pointers and use an unsafe block, which gives you the exact same constraints as you have in C++.

[1] https://doc.rust-lang.org/std/cell/index.html