Bounds

  • When working with generics, the type parameters often must use traits as bounds to stipulate what functionality a type implements

  • The following example uses the trait Display to print and so it requires T to be bound by Display; that is, T must implement Display

// Define a function `printer` that takes a generic type `T` which
// must implement trait `Display`.
fn printer<T: Display>(t: T) {
    println!("{}", t);
}