The primary thing that has bothered me about Pin
is that if you have a Pin<T>
, that means to me that your object is pinned. But in my mind, a Pin<T: Move>
was a misnomer because your T
wasn’t pinned at all. Was Pin
lying?
The alternative mental model I developed for Unpin
was essentially what @GolDDranks was getting at, although I didn’t read their comment at first. get_mut()
or DerefMut
is like unpinning a Pin
temporarily, allowing you to mess with what’s beneath it before putting the pin back (ending your borrow).
Think of taking a thumbtack out of a cork board so you can tweak how a flyer looks. For Unpin
types, this unpinning is directly supported by the type; you can do this implicitly. You can even swap out the object with another before you put the pin back. For other types, you must be much more careful.
I think we can create this mental model on first contact with the trait’s documentation. It’s always going to be the case that when you see a new trait you don’t recognize, you won’t know what to think of it. If you don’t know what a Pin
is, MovePinned
and MoveWhilePinned
are probably going to look just as cryptic to you as Unpin
. And by definition, I don’t know of any object that can move around freely while it’s pinned down, so the longer names may be more confusing after all.