Skip to content

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

Closed
@peter-bertok

Description

@peter-bertok

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-help-wantedCall for participation: Help is requested to fix this issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions