Tracking Issue for seek_io_take
and seek_io_take_position
#97227
Labels
A-io
Area: `std::io`, `std::fs`, `std::net` and `std::path`
C-tracking-issue
Category: An issue tracking the progress of sth. like the implementation of an RFC
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Feature gate:
#![feature(seek_io_take)]
,#![feature(seek_io_take_position)]
(feature gate open to change)
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::Take
by 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
peek
and 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::Take
is notSeek
.Public API
Not yet stabilized API:
Insta-stable in #138023:
This is possible by adding a
cursor
member toio::Take
, together withlimit
, we have:ErrorKind::InvalidInput
(EINVAL).BufReader
doc).The proposed method has an advantage over approach in #37214, by not using an extra
stream_position()
whenio::Take
is constructed.History:
impl<T: Seek> Seek for Take<T>
, introduceTake::position
Addstd::io::Seek
instance forstd::io::Take
#138023The text was updated successfully, but these errors were encountered: