u/Worried_Wrongdoer_35in r/rust • Recommends
On “What was the most difficult topic for you to understand while learning rust?”
111K subscribers • 38 videos on Hallway
Advanced. Deep dive for people who know the field.
78K views5 years ago8 recommendations
Programming languagesSystems programmingRustMemory management
Jon Gjengset explains subtyping and variance in Rust, demonstrating how they affect borrow ergonomics and lifetimes through a strtok implementation.
In this episode of Crust of Rust, we go over subtyping and variance — a niche part of Rust that most people don't have to think about, but which is deeply ingrained in some of Rust's borrow ergonomics, and occasionally manifests in confusing ways. In particular, we explore how trying to implement the relatively straightforward `strtok` function from C/C++ in Rust quickly lands us in a place where the function is more or less impossible to call due to variance! Introduction Practical variance in strtok A simple strtok test Implementing strtok Why can't we call strtok? Pretending to be the compiler Shortening lifetimes Subtypes Covariance Contravariance Invariance &'a mut T covariance in 'a What went wrong in our strtok test? Fixing strtok Why is 'b: 'a not needed? Shortening &'a mut and NLL Is 'b: 'a implied for &'a &'b? Variance, PhantomData, and drop check Reasons for changing variance for{'a} and variance Mutating through *const T NonNull{T} How we got here You can read more about subtyping and variance in the Rust reference @ doc.rust-lang.org/nightly/reference/subtyping.html or in the Nomicon @ doc.rust-lang.org/nomicon/subtyping.html. Live version with chat: youtu.be/--wzpkTuCrAWhat people say. Highly recommended as the definitive explanation of subtyping, variance, and lifetime issues in Rust.
u/Worried_Wrongdoer_35in r/rust • Recommends
On “What was the most difficult topic for you to understand while learning rust?”
u/TheGreaT1803in r/rust • Recommends
On “Thank you to whoever updated the "Subtyping and Variance" section of the Rustonomicon.”
u/riasthebestgirlin r/rust • Recommends
On “So, everyone falls in love with Rust at first sight?”
u/JonhooRust for Rustaceansin r/rust • Recommends
On “Uncovered Intermediate Topics”
u/itamonsterin r/rust • Recommends
On “Why is &mut x active through out main, it shouldn't be active after last reference?”
u/freax13in r/rust • Recommends
On “How is 'static subtype of any lifetime 'a and not supertype?”
u/wezmAllsortsin r/rust • Recommends
On “what is subtyping and variance in layman's terms?”
u/kinoshitajonain r/rust • Recommends
On “Why is &mut x active through out main, it shouldn't be active after last reference?”
u/TheDutchMC76in r/rust • Mentions
On “Rust traits and "+ 'static"”
u/ear7hin r/rust • Mentions
On “What are some good resource to better understand lifetime specifier?”
u/kinoshitajonain r/rust • Mentions
On “Problem with lifetimes in generics”
u/ExasperatedLadybugin r/typescript • Mentions
On “Just found out that you can't trust the TS transpiler with union types. A more complicated version of this made it to production and robbed me of my sanity...”
u/Unusual-Pollution-69in r/rust • Mentions
On “What are some good resource to better understand lifetime specifier?”
u/ondrejdanekin r/rust • Mentions
On “Hey Rustaceans! Got a question? Ask here! (43/2022)!”
u/vortexofdoomin r/rust • Mentions
On “How to make these lifetimes compile”
u/jamincanin r/rust • Mentions
On “What's the difference between `FnOnce`, `Fn` and `FnMut`”