DEV Community

Discussion on: Rust Lifetimes for Safer FFI

Collapse
 
deciduously profile image
Ben Lovy

Excellent write-up! Thanks for this. It's a really good practical example of why lifetimes are so fundamental to Rust and worth getting through the academic understanding. It also demonstrates exactly why Rust wrappers like these are such a good idea and an improvement over using the same API from C.

It's also a good supplement to the example given for PhantomData from the 'nomicon - helpful seeing how it applies to an actual problem.

Collapse
 
jeikabu profile image
jeikabu

The nomicon is great, such a dense treasure trove of information. I mention it in the end, but I probably should have put it in the beginning.

Glad you enjoyed this. I've found I get a lot out of doing these write-ups as a sort of post-mortem for things I'm working on. Forces me to go back and review things with fresh eyes. In the course of posting this I actually realized and fixed a few things. Namely, I had a lifetime on the "root" as well, but turns out it doesn't seem to be necessary...