remove hardcoded BufRead trait bounds#288
Conversation
|
Indeed - thanks for the PR! |
I don't fully understand the original issue though - couldn't you just forward the bound, and have |
|
Yes, that's totally right, but this would require forwarding the |
|
Well, moving from a lifetime parameter to a type parameter is already breaking change, right? You could start with a I agree that omitting the bound in the type definition is nice to have, but I'm not sure it was really a blocker for this? |
|
Hm, you're totally right, sorry! There are a few reasons why this would have been convenient, but I think you're probably right that it's not technically a blocker (sorry again!):
pub struct ZipFile<'a> {
pub(crate) data: Cow<'a, ZipFileData>,
pub(crate) crypto_reader: Option<CryptoReader<'a>>,
pub(crate) reader: ZipFileReader<'a>,
}
Thank you for asking further, because you're absolutely right that this was not a blocker in a real sense. However, |
Problem
Rust structs with generic type parameters are typically not declared with trait bounds on the struct itself, as this makes it difficult to compose into other generic structs. The
zipcrate depends onzstd, and is unable to declare a genericZipFileReaderenum (e.g. https://github.com/zip-rs/zip2/blob/b6e0a0693ba2d07f541cd9017b60df7e65817e48/src/read.rs#L190) without creating a vtable&'a mut dyn Read, since theR: BufReadbound on theDecoderstruct declaration requires a concrete type implementingBufRead, whereasio::BufReaderdoesn't have the sameR: Readbound on the struct declaration.In essence, we currently have this:
but we would like to be able to have this instead:
This avoids the creation of a vtable indirection and unnecessary lifetime bound.
Solution
Remove the
R: BufReadbounds on theEncoderandDecoderstruct declarations.Result
This is not a breaking change.