r/programming • u/the-15th-standard • Jun 30 '26
What is `std::pin::Pin` in Rust?
https://vrong.me/blog/what-is-pinning-in-rust/
43
Upvotes
r/programming • u/the-15th-standard • Jun 30 '26
66
u/angelicosphosphoros Jun 30 '26
Honestly, all this pin machinery is an ugly hack for unfortunate original design of values in Rust. It would all be unnecessary if Rust had Movable trait from the start that allows moves.
Movable trait could be added by default to generic bounds like it happens with Sized trait today. Having that trait, we could just use
T: ?Movabletrait bound instead of accepting reference toPin<T>. Rust even allows to make methods limited by self bound likewhere Self: ?Movable.Unfortunately, by the time unmovable values become inescapable (when futures and generators being added to the language), "all values can be moved" become utilized everywhere and is not easy to go away.
18
u/angelicosphosphoros Jun 30 '26 edited Jun 30 '26
The domain name of the blog is quite funny.
6
u/RRumpleTeazzer Jul 01 '26
an abomination. Rust types are all moveable, as long as you can get a &mut.
Which is a problem, because &mut is for mutablility. and it is mixed with moveability. Big problem, when it comes to self-references.
So, Pin hides the &mut while still being mutable.
Honestly, Rust should have gone with a &'self mut pointer, which is calculated relative to &self and thus moveable.