Skip to content
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

Make std::io::Take<R> an instance of std::io::Seek when R:std::io::Seek #37214

Open
ghost opened this issue Oct 16, 2016 · 3 comments
Open

Make std::io::Take<R> an instance of std::io::Seek when R:std::io::Seek #37214

ghost opened this issue Oct 16, 2016 · 3 comments
Labels
A-io Area: std::io, std::fs, std::net and std::path C-feature-accepted Category: A feature request that has been accepted pending implementation. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@ghost
Copy link

ghost commented Oct 16, 2016

This would be particularly useful for reading file formats containing other formats.
Examples include:

  • OpenType font files, where CFF is an embedded format.
  • GRIB (format used by weather forecast organisms), containing grayscale JPEG to describe values.

(and probably many others)
In such cases, it would also be cool to have a "drain" method on std::io::Take, that would move the read cursor at the end of the Take.

@sfackler
Copy link
Member

How would this implementation behave when SeekFrom::Start or SeekFrom::End is passed?

@ghost
Copy link
Author

ghost commented Oct 16, 2016

Well, for my particular use case, it would be most useful to see a "subfile", hence, if len is the length passed to take:

  • take does a seek(SeekFrom::Current(0)) to determine the current position at the moment take(len) is called, let's call that position offset.
  • then SeekFrom::Start(n) actually performs a SeekFrom::Start(offset+n) on the underlying Seek.
  • SeekFrom::End(n) does SeekFrom::Start(offset + len + n) on the underlying Seek.

@steveklabnik steveklabnik added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed A-libs labels Mar 24, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 26, 2017
@dtolnay dtolnay added C-feature-accepted Category: A feature request that has been accepted pending implementation. and removed C-feature-request Category: A feature request, i.e: not implemented / a PR. labels Nov 18, 2017
@dtolnay
Copy link
Member

dtolnay commented Nov 18, 2017

I am not 100% sold on the proposed implementation, but I would be interested in seeing a well-tested PR for adding this impl. I agree that seeking within a "subfile" seems reasonable.

@Enselic Enselic added the A-io Area: std::io, std::fs, std::net and std::path label Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-io Area: std::io, std::fs, std::net and std::path C-feature-accepted Category: A feature request that has been accepted pending implementation. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants