Generics
Last Updated: 2021-11-19
Generics: Similar to the way a function takes parameters with unknown values to run the same code on multiple concrete values, functions can take parameters of some generic type instead of a concrete type.
Rust: Code doesn’t run any slower using generic types than it would with concrete types.
Rust accomplishes this by performing monomorphization of the code that is using generics at compile time. Monomorphization is the process of turning generic code into specific code by filling in the concrete types that are used when compiled. the compiler looks at all the places where generic code is called and generates code for the concrete types the generic code is called with.