mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-01-09 01:02:47 +02:00
Update trait-bounds.md (#248)
Mentioning `where` clause syntax in speaker notes.
This commit is contained in:
parent
b75e713792
commit
cde1c433f6
@ -15,3 +15,22 @@ fn main() {
|
||||
let pair = duplicate(foo);
|
||||
}
|
||||
```
|
||||
|
||||
<details>
|
||||
|
||||
Consider showing a `where` clause syntax. Students can encounter it too when reading code.
|
||||
|
||||
```rust,ignore
|
||||
fn duplicate<T>(a: T) -> (T, T)
|
||||
where
|
||||
T: Clone,
|
||||
{
|
||||
(a.clone(), a.clone())
|
||||
}
|
||||
```
|
||||
|
||||
* It declutters the function signature if you have many parameters.
|
||||
* It has additional features making it more powerful.
|
||||
* If someone asks, the extra feature is that the type on the left of ":" can be arbitrary, like `Option<T>`.
|
||||
|
||||
</details>
|
||||
|
Loading…
Reference in New Issue
Block a user