Skip to content

Commit

Permalink
Remove trait bound on VerbosityFilter in the generic data types sli…
Browse files Browse the repository at this point in the history
…de (#2603)

It's generally more idiomatic in Rust to not have trait bounds on the
data type itself. I think we better demonstrate how trait bounds are
used in impl blocks with generic data types in the impl block below the
struct definition. I've also added a speaker note to call this out if
students ask.
  • Loading branch information
randomPoison authored Feb 3, 2025
1 parent 43e1cd6 commit abf9393
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/generics/generic-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl Logger for StderrLogger {
}
/// Only log messages up to the given verbosity level.
struct VerbosityFilter<L: Logger> {
struct VerbosityFilter<L> {
max_verbosity: u8,
inner: L,
}
Expand Down Expand Up @@ -53,5 +53,8 @@ fn main() {
- `VerbosityFilter` is still generic and you can use `VerbosityFilter<f64>`,
but methods in this block will only be available for
`Point<StderrLogger>`.
- Note that we don't put a trait bound on the `VerbosityFilter` type itself. You
can put bounds there as well, but generally in Rust we only put the trait
bounds on the impl blocks.

</details>

0 comments on commit abf9393

Please sign in to comment.