Skip to content

Commit c253b33

Browse files
authored
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.
1 parent 39d0588 commit c253b33

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/closures/solution.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,12 @@
33
```rust,editable
44
{{#include exercise.rs:solution}}
55
```
6+
7+
<details>
8+
9+
- Note that the `P: Fn(u8, &str) -> bool` bound on the first `Filter` impl block
10+
isn't strictly necessary, but it helps with type inference when calling `new`.
11+
Demonstrate removing it and showing how the compiler now needs type
12+
annotations for the closure passed to `new`.
13+
14+
</details>

0 commit comments

Comments
 (0)