-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Tracking Issue for seek_io_take
and seek_io_take_position
#97227
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
Comments
…tgross35 Add `std::io::Seek` instance for `std::io::Take` Library tracking issue [rust-lang#97227](rust-lang#97227). ACP: rust-lang/libs-team#555 1. add a `len` field to `Take` to keep track of the original number of bytes that `Take` could read 2. add a `position()` method to return the current position of the cursor inside `Take` 3. implement `std::io::Seek` for `std::io::Take` Closes: rust-lang/libs-team#555
as mentioned previously: #138023 (review) this tracking issue needs to be updated to include position and seek_io_take_position. |
Add `std::io::Seek` instance for `std::io::Take` Library tracking issue [#97227](rust-lang/rust#97227). ACP: rust-lang/libs-team#555 1. add a `len` field to `Take` to keep track of the original number of bytes that `Take` could read 2. add a `position()` method to return the current position of the cursor inside `Take` 3. implement `std::io::Seek` for `std::io::Take` Closes: rust-lang/libs-team#555
seek_io_take
and seek_io_take_position
…tgross35 Add `std::io::Seek` instance for `std::io::Take` Library tracking issue [rust-lang#97227](rust-lang#97227). ACP: rust-lang/libs-team#555 1. add a `len` field to `Take` to keep track of the original number of bytes that `Take` could read 2. add a `position()` method to return the current position of the cursor inside `Take` 3. implement `std::io::Seek` for `std::io::Take` Closes: rust-lang/libs-team#555
This doesn't match the current implementation which returns And
I think this should say reads beyond the original limit return |
Uh oh!
There was an error while loading. Please reload this page.
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: