rsRustPrimer
< Back to modules

Traits and generics

Polymorphism the Rust way: shared behavior, with zero runtime cost.

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