Where clauses
A bound can also be expressed using a where clause immediately
before the opening {, rather than at the type's first mention.
Additionally, where clauses can apply bounds to arbitrary types,
rather than just to type parameters.
Some cases that a where clause is useful:
- When specifying generic types and bounds separately is clearer:
impl <A: TraitB + TraitC, D: TraitE + TraitF> MyTrait<A, D> for YourType {}
// Expressing bounds with a `where` clause
impl <A, D> MyTrait<A, D> for YourType where
A: TraitB + TraitC,
D: TraitE + TraitF {}
- When using a
whereclause is more expressive than using normal syntax. Theimplin this example cannot be directly expressed without awhereclause: