Closed
Description
Example from flate2:
pub struct EncoderReader<R: Read> {
inner: EncoderReaderBuf<BufReader<R>>,
}
Bounds like this are annoying because they transitively infect any structs containing this type. Usually trait bounds should go just on impl blocks, not on data structures.
There are two exceptions where trait bounds on data structures are required.
- The data structure refers to an associated type of the trait.
Cow
is an example of this. - The data structure has a Drop impl that requires trait bounds. Rust currently requires all bounds on the Drop impl to also be present on the data structure.
Relevant flate2 issue: rust-lang/flate2-rs#88