Add {BufWriter,BufReader}::buffer() to BufRead trait

In Rust v1.37, the BufReader and BufWriter structs both added a buffer() -> &[u8] method that allowed users to access the struct's buffer directly without attempting to refill it (as fill_buf() -> &[u8] does).

I was surprised to see that this method was not also added to the BufRead trait. A user noted this on the tracking issue, but the change was merged and the issue closed out without further discussion.

Since trait specialization isn't stable yet, it's not possible leverage buffer() in blanket trait implementations. Is there a good reason not to add this to BufRead?

How would that method be added without breaking backwards compatibility?

Good point. The only ways I can think of seem hacky. Is this something that could be added in a new edition, or is that restricted to syntactic changes?

Editions cannot change the definitions of traits.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.