Skip to content

Commit cde1c43

Browse files
authored
Update trait-bounds.md (#248)
Mentioning `where` clause syntax in speaker notes.
1 parent b75e713 commit cde1c43

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/generics/trait-bounds.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,22 @@ fn main() {
1515
let pair = duplicate(foo);
1616
}
1717
```
18+
19+
<details>
20+
21+
Consider showing a `where` clause syntax. Students can encounter it too when reading code.
22+
23+
```rust,ignore
24+
fn duplicate<T>(a: T) -> (T, T)
25+
where
26+
T: Clone,
27+
{
28+
(a.clone(), a.clone())
29+
}
30+
```
31+
32+
* It declutters the function signature if you have many parameters.
33+
* It has additional features making it more powerful.
34+
* If someone asks, the extra feature is that the type on the left of ":" can be arbitrary, like `Option<T>`.
35+
36+
</details>

0 commit comments

Comments
 (0)