mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-03-27 16:25:43 +02:00
Remove trait bound on VerbosityFilter
in the generic data types slide (#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.
This commit is contained in:
parent
43e1cd6c49
commit
abf9393e60
@ -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,
|
||||
}
|
||||
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user