Skip to content

Commit

Permalink
Rollup merge of rust-lang#100520 - jakubdabek:patch-1, r=thomcc
Browse files Browse the repository at this point in the history
Add mention of `BufReader` in `Read::bytes` docs

There is a general paragraph about `BufRead` in the `Read` trait's docs, however using `bytes` without `BufRead` *always* has a large impact, due to reads of size 1.

`@rustbot` label +A-docs
  • Loading branch information
matthiaskrgr authored Aug 28, 2022
2 parents 58174e3 + 8509936 commit 83e8305
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion library/std/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,10 @@ pub trait Read {
/// The yielded item is [`Ok`] if a byte was successfully read and [`Err`]
/// otherwise. EOF is mapped to returning [`None`] from this iterator.
///
/// The default implementation calls `read` for each byte,
/// which can be very inefficient for data that's not in memory,
/// such as [`File`]. Consider using a [`BufReader`] in such cases.
///
/// # Examples
///
/// [`File`]s implement `Read`:
Expand All @@ -899,10 +903,11 @@ pub trait Read {
/// ```no_run
/// use std::io;
/// use std::io::prelude::*;
/// use std::io::BufReader;
/// use std::fs::File;
///
/// fn main() -> io::Result<()> {
/// let f = File::open("foo.txt")?;
/// let f = BufReader::new(File::open("foo.txt")?);
///
/// for byte in f.bytes() {
/// println!("{}", byte.unwrap());
Expand Down

0 comments on commit 83e8305

Please sign in to comment.