-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
zip
crate depends onzstd
, and is unable to declare a genericZipFileReader
enum (e.g. https://github.com/zip-rs/zip2/blob/b6e0a0693ba2d07f541cd9017b60df7e65817e48/src/read.rs#L190) without creating a vtable&'a mut dyn Read
, since theR: BufRead
bound on theDecoder
struct declaration requires a concrete type implementingBufRead
, whereasio::BufReader
doesn't have the sameR: Read
bound 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: BufRead
bounds on theEncoder
andDecoder
struct declarations.Result
This is not a breaking change.