topic: generics
generics let functions and structs work over multiple types while staying type-safe.
concepts to demonstrate
- generic function syntax
fn top_n<T: Ord>(items: &[T], n: usize) -> Vec<&T>
- generic structs:
StatLeader<T>
- trait bounds:
where T: Display + PartialOrd
- monomorphization (rust compiles one version per concrete type used)
patriots theme
generic top_n that works on rushing yards, receiving yards, or passing rating.
StatLeader<Player> struct holding a typed winner and their value.
file
src/generics/roster_query.rs