1
0
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:
Nicole L
2025-06-26 12:09:38 -07:00
committed by GitHub
parent 39d0588c89
commit c253b33977

View File

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