Trait bounds in Rust are really powerful and also offers lots of idiomatic ways to constrain your model. Bounds are for enforcing constraints even in other languages like Scala, but Rust offers them at a different level.
Here's one example from the book Rust for Rustaceans (a great book BTW).
Suppose you want to construct a HashMap<K, V, S>
, whose keys are some generic type T
, value is a usize
, you can write bounds like T: Hash + Eq
, S: BuildHasher + Default
.
pub fn doit<T>(value: T)