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

**URL:** <https://internals.rust-lang.org/t/add-bufwriter-bufreader-buffer-to-bufread-trait/13668>\
**Category:** Uncategorized\
**Created:** [December 22, 2020, 3:43pm UTC](https://internals.rust-lang.org/t/add-bufwriter-bufreader-buffer-to-bufread-trait/13668 "2020-12-22T15:43:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zslayton](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/zslayton/32/7522_2.png) [@zslayton](https://internals.rust-lang.org/u/zslayton)\
**Post date:** [December 22, 2020, 3:43pm UTC](https://internals.rust-lang.org/t/add-bufwriter-bufreader-buffer-to-bufread-trait/13668/1 "2020-12-22T15:43:22Z")

</div>

In Rust v1.37, the `BufReader` and `BufWriter` structs both added a [`buffer() -> &[u8]`](https://doc.rust-lang.org/std/io/struct.BufReader.html#method.buffer) method that allowed users to access the struct's buffer directly without attempting to refill it (as [`fill_buf() -> &[u8]`](https://doc.rust-lang.org/std/io/trait.BufRead.html#tymethod.fill_buf) 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](https://github.com/rust-lang/rust/issues/45323#issuecomment-495822066), 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`?

---

<div class="post-metadata">

**Author:** ![sfackler](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/sfackler/32/9_2.png) [@sfackler](https://internals.rust-lang.org/u/sfackler)\
**Post date:** [December 22, 2020, 4:01pm UTC](https://internals.rust-lang.org/t/add-bufwriter-bufreader-buffer-to-bufread-trait/13668/2 "2020-12-22T16:01:46Z")

</div>

How would that method be added without breaking backwards compatibility?

---

<div class="post-metadata">

**Author:** ![zslayton](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/zslayton/32/7522_2.png) [@zslayton](https://internals.rust-lang.org/u/zslayton)\
**Post date:** [December 22, 2020, 4:30pm UTC](https://internals.rust-lang.org/t/add-bufwriter-bufreader-buffer-to-bufread-trait/13668/3 "2020-12-22T16:30:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sfackler](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/sfackler/32/9_2.png) [@sfackler](https://internals.rust-lang.org/u/sfackler)\
**Post date:** [December 22, 2020, 6:01pm UTC](https://internals.rust-lang.org/t/add-bufwriter-bufreader-buffer-to-bufread-trait/13668/4 "2020-12-22T18:01:35Z")

</div>

Editions cannot change the definitions of traits.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 22, 2021, 6:01pm UTC](https://internals.rust-lang.org/t/add-bufwriter-bufreader-buffer-to-bufread-trait/13668/5 "2021-03-22T18:01:36Z")

</div>

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