A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rust-lang/rust/issues/97227 below:

Tracking Issue for `seek_io_take` and `seek_io_take_position` · Issue #97227 · rust-lang/rust · GitHub

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 new io::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 restore stream_position() depends on what data was peek-ed, skip a large chunk of unwanted bytes, or maybe we simply wanted to keep track of the stream_position() for better error handling. This is not possible because io::Take is not Seek.

Public API

Not yet stabilized API:

impl<T> Take<T> {
    // Unstable as `seek_io_take_position`
    pub fn position(&self) -> u64;
}

Insta-stable in #138023:

// Stabilized as `seek_io_take`
impl<T: Seek> Seek for Take<T> {
    fn seek(&mut self, pos: SeekFrom) -> Result<u64> {
        // snip
    }
}

This is possible by adding a cursor member to io::Take, together with limit, we have:

The proposed method has an advantage over approach in #37214, by not using an extra stream_position() when io::Take is constructed.

History:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4