Hacker News new | past | comments | ask | show | jobs | submit login

> The use of a special kind of lifetime annotation, where the lifetime has to match exactly, can be used to get around this limitation.

This is already expressible in Rust, using invariant lifetimes. You can hand someone an opaque invariant lifetime, let them build a mutable cyclic data structure with it, and then pass that data structure around.

This use of invariant lifetimes, called "generativity," is described in more detail here (https://raw.githubusercontent.com/Gankro/thesis/master/thesi...) in section 6.3, which describes a way to use lifetimes as unique tokens for all sorts of use cases.

And even more closely aligned with what the article is talking about, Catherine West has put together a library that uses generativity to provide a safe interface to a garbage collected heap, as part of a reimplementation of Lua: the `gc-arena` crate in https://github.com/kyren/luster




Generativity is truly the most mysterious part of Rust type system. Like template metaprogramming in C++, I see the great (ab)use potential in the future.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: