Monomorphization

Generic code is turned into non-generic code based on the call sites:

  1. fn main() {
  2. let integer = Some(5);
  3. let float = Some(5.0);
  4. }

behaves as if you wrote

  1. enum Option_i32 {
  2. Some(i32),
  3. None,
  4. }
  5. enum Option_f64 {
  6. Some(f64),
  7. None,
  8. }
  9. fn main() {
  10. let integer = Option_i32::Some(5);
  11. let float = Option_f64::Some(5.0);
  12. }

This is a zero-cost abstraction: you get exactly the same result as if you had hand-coded the data structures without the abstraction.