u/Merzbroin r/rust • Recommends
On “How to get a trait object for one auto-trait and one trait”
#dynamicdispatch#staticdispatch#vtables
111K subscribers • 38 videos on Hallway
Intermediate. Assumes working knowledge.
107K views5 years ago2 recommendations
Programming languagesSystems programmingRustPerformance and optimizationMemory management
Jon Gjengset explains static and dynamic dispatch in Rust, diving deep into generics, monomorphization, trait objects, and vtables.
In this episode of Crust of Rust, we go over static and dynamic dispatch in Rust by diving deep into generics, monomorphization, and trait objects. As part of that, we also discuss what exactly the Sized trait is, what it's for, and how it interacts with Dynamically Sized traits. Introduction Monomorphization (Static) Dispatch Trait Objects The Sized Trait Sizing Unsized Types Can I Recover The Concrete Type? Dynamic Dispatch Vtables Limitation: Multiple Traits Limitation: Associated Types Limitation: Static Trait Methods Disallowing Trait Objects Limitation: Generic Methods Limitation: No Non-Receiver Self Partial Object Safety Dropping Trait Objects Dynamically Sized Types Manual Vtables in std Q&A: Making Your Own DST Box([u8]) vs. Vec(u8) dyn Fn() vs. fn() vs. impl Fn() No Coherence This Stream Runtime Trait Detection Double-Dereferencing dyn Fn() Unsafe Vtable Comparions Slice of Trait Objects Codegen Units and Vtables The Any Trait You can read more about Rust monomorphization in the Rust book at doc.rust-lang.org/book/ch10-01-syntax.html?highlight=perform…. It also has some good discussion about Trait Objects (doc.rust-lang.org/book/ch17-02-trait-objects.html) and Dynamically Sized Types (doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamical…). For more details, the Rust reference also has more details on Trait Objects (doc.rust-lang.org/nightly/reference/types/trait-object.html) and Object Safety (doc.rust-lang.org/nightly/reference/items/traits.html#object…), and so does the Rustonomicon (doc.rust-lang.org/nomicon/exotic-sizes.html). Live version with chat: youtu.be/TOwiCW8zXzUWhat people say. Recommended as an excellent, detailed explanation of dynamic dispatch, trait objects, and object safety in Rust.
u/Merzbroin r/rust • Recommends
On “How to get a trait object for one auto-trait and one trait”
u/charlesdartin r/rust • Recommends
On “Hey Rustaceans! Got an easy question? Ask here (20/2021)!”
u/vzwGreyin r/rust • Mentions
On “How to get a trait object for one auto-trait and one trait”