Traits and generics
Polymorphism the Rust way: shared behavior, with zero runtime cost.
- 1Defining and implementing a traitA behavior contract, implemented type by type.
- 2Standard library traitsderive, Display, From: the traits everyone expects.
- 3GenericsWrite a function once, for every type that satisfies a trait.
- 4Trait objects and dynMix different types in the same collection.
- ◆Project: diffusion modelsRunning projectA DiffusionModel trait, two models, and the first Monte Carlo simulation.