๐ฆ Rust Generic Functions
= generic functions
- syntax:
fn <Type: Trait> fn_name...
- multiple types:
fn <Type: Trait, Type2: Trait2> fn_name...
- shorter:
fn <T, R> fn_name () -> Results where M: ..., R: ...
- shorter:
๐ Example:
// Takes two parameters val_1, val_2 of type T
// Type T has to implement Trait Ord
fn min<T: Ord>(val_1: T, val_2: T) -> T {...}
๐ Links