Rust traits act as generic constraints
(Jin Qing's Column, Nov. 18, 2021)
Rust traits are different from interfaces of C++/Java/Go.
Rust traits are mechanism for adding behavior to types.
Traits have 2 modes. One is interface as Java.
Another is generic constraint. Generic functions are defined over types that implemented specific traits.
The "complie-time duck typing" in C++ templates is avoided in Rust.
Rust will reject a type with quack() method as a Duck type.
We must pass a type which implements Duck trait.
But in Go, a type with quack() method is sufficient to be used as a Duck interface.