-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Tracking Issue for seek_io_take and seek_io_take_position #97227
Copy link
Copy link
Open
Labels
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Feature gate:
#![feature(seek_io_take)],#
This is a tracking issue for adding seek instance for
io::Take, see issue #37214.Why
Imagine there's a smaller components within a larger file, the component have predefined ranges, reading beyond the range should be a hard error. But some fields are variable size encoded, so it's hard to know how many bytes to read until we already decoded/read a large part of it. It is super cumbersome to check every read is within the limit (of the component); however, with
io::Take, this is much easier: We only need to create a newio::Takeby limiting the upper bound to the component's spec. and just let the user to read what ever needed -- any attempt to read beyond the limit would cause a hard io error.This is all good, but sometimes we need more powerful io rather than read. For instance, we may need
peekand restorestream_position()depends on what data waspeek-ed, skip a large chunk of unwanted bytes, or maybe we simply wanted to keep track of thestream_position()for better error handling. This is not possible becauseio::Takeis notSeek.Public API
Not yet stabilized API:
Insta-stable in #138023:
This is possible by adding a
cursormember toio::Take, together withlimit, we have:ErrorKind::InvalidInput(EINVAL).BufReaderdoc).The proposed method has an advantage over approach in #37214, by not using an extra
stream_position()whenio::Takeis constructed.History:
impl<T: Seek> Seek for Take<T>, introduceTake::positionAddstd::io::Seekinstance forstd::io::Take#138023