The Pin type (and the concept of pinning in general) is a foundational building block on which
the rest of the the Rust async ecosystem stands. Unfortunately, it has also been one of the least
accessible and most misunderstood elements of async Rust. This post is meant to explain what Pin
achieves, how it came to be, and what the current problem with Pin is.
There was an interesting post a few months ago on the blog of the company Modular, which is
developing a new language called Mojo. In a brief section discussing Pin in Rust, I found that it
very succinctly captured the zeitgeist of the public discussion of the subject:
In Rust, there is no concept of value identity. For a self-referential struct pointing to its own
member, that data can become invalid if the object moves, as it’ll be pointing to the old location
in memory. This creates a complexity spike, particularly in parts of async Rust where futures need
to be self-referential and store state, so you must wrap Self with Pin to guarantee it’s not going
to move. In Mojo, objects have an identity so referring to self.foo will always return the correct
location in memory, without any additional complexity required for the programmer.
Keep reading
Out of respect for the author only the opening is shown here. Read the rest on the original site, or in HorizonReader with highlights, notes and AI help.
In July, I described a way to make pinning more ergonomic by integrating it more fully into the language. Last week, I develoepd that idea further with the notion of UnpinCell: a wrapper type that lets a user take an &pin mut UnpinCell<T> a
A variation on my previous design for pinned places has occurred to me that would be more consistent with Rust’s existing feature set. The most outlandish aspect of the previous design was the notion of “pinned fields,” which support pinned
In the previous post, I described the goal of Rust’s Pin type and the history of how it came to exist. When we were initially developing this API in 2018, one of our explicit goals was the limit the number of changes we would make to Rust,
This post is meant as an explainer about how substructural type theory can be applied in programming language design. Terms like “substructural type theory” tend to scare and confuse programmers who don’t write Haskell on the weekends, so o
In a high-level language, the programmer is deprived of the dangerous power to update his own program while it is running. Even more valuable, he has the power to split his machine into a number of separate variables, arrays, files, etc.; w