-
Notifications
You must be signed in to change notification settings - Fork 40
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
read_zipfile_from_stream takes reference to R: Read, instead of R: Read #177
Comments
It does not really make sense to take ownership of the reader for most use-cases. Why not just return the Vec and parse the zipfile at a later time? Or use the normal zip parsing methods? |
An owned generic parameter wouldn't need to take ownership of the reader - One little thing is that this will have to wait for the next (pre-)release since it would technically be a breaking change for some edge cases. |
I also found this API particularly troublesome for composition: Imagine you have a Having struct ZipDecoder<R: Read> {
reader: R,
zip_file: ZipFile<?> // references reader somehow???
} because as far as I understand one member holding a |
Yep, I also had this problem. I wanted to create a reader that concatenates multiple files inside a zip file to one contiguous reader. I ended up using |
@Plecra's argument makes sense, this indeed makes more sense. |
We have a slight issue in the implementation: A I doubt it'll be possible to make them the same type, which means we aren't going to be able to have a |
I'm currently encountering an issue in design of a program that uses the zip crate centered around the function zip::read::read_zipfile_from_stream. I'm using it to create a zipfile struct, however, because read_zipfile_from_stream takes a reference to something implementing the read trait, instead of something taking the read trait itself, I'm finding it impossible to use this function in this instance. That's because I actually pass the ZipFile struct up out of the body where the Vec, and it's corresponding slice, are created that initialize the ZipFile, meaning that I end up invalidating the reference, because the reference refers to the Vec, however, the vec is dropped at the end of the function, whereas the ZipFile is supposed to live beyond that. This issue is intractable because I cannot move where I read the bytes from the stream a level up, and I have designed my own interfaces to take not a reference to something implementing Read, but to borrow something implementing Read. For the reasons above, I need a function exactly like read_zipfile_from_stream, but that does not take a reference. Is this possible to add to the zip crate? Its presence would make possible a much wider range of use cases for read_zipfile_from_stream than are currently possible.
In practice, here's how this occurs:
In practice, it looks like this may be difficult because you've implemented everything in terms of taking references: for instance, your interfaces in podio that are relied upon take mutable references to read. I will think about how this might be overcome.
The text was updated successfully, but these errors were encountered: