Trait Bounds
Constrain generics with traits.
What Trait Bounds Do
A trait bound restricts a generic type to those that implement a given trait. It tells the compiler what behavior the type guarantees.
This unlocks the trait's methods inside the generic code while keeping the function usable for many types.
Inline Bound Syntax
The simplest form places the bound right after the type parameter: T: Trait. Here T must implement Display so it can be printed.
Inside the function you may now call any method that Display provides.
use std::fmt::Display;
fn show<T: Display>(value: T) {
println!("value = {}", value);
}