You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-07-03 21:39:51 +02:00
Add note about trait bound in closures exercise (#2788)
I've tried removing this trait bound thinking it's unnecessary only to then be surprised that it breaks type inference. I think that's worth calling out to students, so I think a speaker note here would be appropriate.
This commit is contained in:
@ -3,3 +3,12 @@
|
||||
```rust,editable
|
||||
{{#include exercise.rs:solution}}
|
||||
```
|
||||
|
||||
<details>
|
||||
|
||||
- Note that the `P: Fn(u8, &str) -> bool` bound on the first `Filter` impl block
|
||||
isn't strictly necessary, but it helps with type inference when calling `new`.
|
||||
Demonstrate removing it and showing how the compiler now needs type
|
||||
annotations for the closure passed to `new`.
|
||||
|
||||
</details>
|
||||
|
Reference in New Issue
Block a user