๐Ÿฆ„ 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: ...

๐Ÿ“– 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

๐Ÿ‘จโ€๐Ÿš€ Rust Traits