0:00 / 0:00
RustConf 2021 - Move Constructors: Is it Possible? by Miguel Young de la Sota
Rust Programming Language
70K subscribers • 43 videos on Hallway • Conference channel
- Recommended by 2 people: 1 on Lobsters and 1 in engineering communities.
- Presented by Miguel Young de la Sota
Advanced. Deep dive for people who know the field.
9.4K views5 years ago2 recommendations
Programming languagesSystems programmingRustC++Memory management
Miguel Young de la Sota explains how to implement C++ style move constructors in Rust using Pin guarantees.
Move Constructors: Is it Possible? by Miguel Young de la Sota A "self-referential" type is one that holds a reference into itself; async Futures are the most common self-referential types in Rust today. However, they can't be moved without invalidating the reference, so they're pinned on the heap or stack. You can't return them or put them into collections (without Boxing, of course). C++ makes heavy use of safely-moveable self-referential types, via move constructors. Bridging move constructors into Rust is one of the great unsolved problems of C++ FFI. Was an unsolved problem. Using a novel interpretation of the Pin P guarantees, we'll port all C++ constructors, not just move constructors, to Rust, without compromising Rust's move-after-use protections (something C++ lacks). Return-by-move and collections are fully supported in today's stable Rust. Beyond zero-cost C++ FFI, Rust "constructors" can be applied to express novel data structures in pure Rust. No C++ knowledge required!Why it's here
2 people recommend thisWhat people say. Recommended as a solution for handling self-referential types and C++ FFI move constructors in Rust.
u/mmstickin r/ProgrammingLanguages • Recommends
On “C Isn't A Programming Language Anymore - Faultlore”
> Lel. Imagine a systems language that cannot even allocate directly on the heap.
I got your example working succinctly, therefore this statement is invalid. There's only a flaw with how `Box::new()` works, and `placement new` will fix that once it's been implemented.
You can also see https://github.com/google/moveit as a crate for solving similar problems like this right now, with this conference talk from the author.
> How much Rust is actually used in the industry (not hobby projects)? 1%?
At this point, probably 90% of companies are now building and relying on projects written in Rust. Check who the sponsors are for the Rust Foundation.
> https://www.reddit.com/r/rust/comments/th3…