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

Allow pub access to underlying 'Read' member of Take or Chain #29067

Closed
peter-bertok opened this Issue Oct 15, 2015 · 5 comments

Comments

Projects
None yet
6 participants
@peter-bertok
Copy link

peter-bertok commented Oct 15, 2015

I asked this as a question on StackOverflow, and it was suggested that I raise an issue.

I'm writing a Rust implementation of the Google Brotli decompression algorithm, which uses a fixed number of "implicit zeroes" at the end of the stream to enable certain optimisations.

The Google C implementation does this using a spaghetti code of various counters, but I'd like to use the adaptors in the Rust std::io library instead. Something like:

pub struct StreamBitReader<R> {
    reader: Chain<R,Take<Repeat>>,
    ...
}

where 'R' is the underlying Read that the bit reader struct is wrapping. However, there are a number of cases where the decompression algorithm checks to see if it has "overrun" the stream, and it does this by checking the number of implicit zero bytes that have been read. This appears to be impossible in safe Rust, as there is no way to obtain a reference to the underlying components of Chain, unless I'm missing something.

When Chain is constructed, it takes ownership of (moves) the two Read structs, which then are hidden in private members.

Is there any way to construct the Take<Repeat> part such that I can continue to access the limit() fn of Take even after the Chain adaptor takes ownership?

If not, then there ought to be either public members or functions that allow access to the base Read members of all such adaptors, to allow this type of code.

@sfackler

This comment has been minimized.

Copy link
Member

sfackler commented Oct 15, 2015

That seems pretty reasonable. We already have those kinds of accessors on other adaptors like BufferedReader and BufferedWriter.

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Mar 23, 2017

Does libs team care about this for completeness?

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Mar 23, 2017

Yes seems fine to implement to me

@aturon aturon added E-help-wanted and removed I-nominated labels Mar 28, 2017

@aturon

This comment has been minimized.

Copy link
Member

aturon commented Mar 28, 2017

Libs team is 👍 on this, please send a PR!

@SergioBenitez

This comment has been minimized.

Copy link
Contributor

SergioBenitez commented Apr 22, 2017

I've started working on this and will have an implementation soon!

SergioBenitez added a commit to SergioBenitez/rust that referenced this issue Apr 22, 2017

SergioBenitez added a commit to SergioBenitez/rust that referenced this issue Apr 22, 2017

SergioBenitez added a commit to SergioBenitez/rust that referenced this issue Apr 22, 2017

SergioBenitez added a commit to SergioBenitez/rust that referenced this issue Apr 23, 2017

SergioBenitez added a commit to SergioBenitez/rust that referenced this issue Apr 24, 2017

frewsxcv added a commit to frewsxcv/rust that referenced this issue Apr 25, 2017

Rollup merge of rust-lang#41463 - SergioBenitez:master, r=alexcrichton
Add internal accessor methods to io::{Chain, Take}.

Resolves rust-lang#29067.

arielb1 pushed a commit to arielb1/rust that referenced this issue Apr 25, 2017

Ariel Ben-Yehuda
Rollup merge of rust-lang#41463 - SergioBenitez:master, r=alexcrichton
Add internal accessor methods to io::{Chain, Take}.

Resolves rust-lang#29067.

arielb1 pushed a commit to arielb1/rust that referenced this issue Apr 25, 2017

Ariel Ben-Yehuda
Rollup merge of rust-lang#41463 - SergioBenitez:master, r=alexcrichton
Add internal accessor methods to io::{Chain, Take}.

Resolves rust-lang#29067.

frewsxcv added a commit to frewsxcv/rust that referenced this issue Apr 26, 2017

Rollup merge of rust-lang#41463 - SergioBenitez:master, r=alexcrichton
Add internal accessor methods to io::{Chain, Take}.

Resolves rust-lang#29067.

@bors bors closed this in #41463 Apr 26, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.