Generic Functions
Parameterize behavior by type.
Why Generic Functions
Generic functions let you write one function that works with many types instead of copying code per type. Rust replaces the placeholder type at compile time.
Imagine writing one largest for integers and another for chars. Generics collapse those into a single definition with no runtime cost.
Type Parameters
A generic function declares a type parameter inside angle brackets after the name. The name T is a convention, but any CamelCase identifier works.
The parameter can then appear in arguments and the return type, standing in for whatever concrete type the caller uses.
fn first<T>(pair: (T, T)) -> T {
pair.0
}