1
0
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:
Igor Petruk 2023-01-23 13:39:23 +00:00 committed by GitHub
parent b75e713792
commit cde1c433f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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>