Skip to content

Commit 541fe5f

Browse files
committed
Auto merge of #25610 - mbrubeck:bufread-docs, r=alexcrichton
r? @steveklabnik
2 parents 749cb19 + d776191 commit 541fe5f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/libstd/io/buffered.rs

+18
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ use iter;
2727
/// For example, every call to `read` on `TcpStream` results in a system call.
2828
/// A `BufReader` performs large, infrequent reads on the underlying `Read`
2929
/// and maintains an in-memory buffer of the results.
30+
///
31+
/// # Examples
32+
///
33+
/// ```no_run
34+
/// use std::io::prelude::*;
35+
/// use std::io::BufReader;
36+
/// use std::fs::File;
37+
///
38+
/// # fn foo() -> std::io::Result<()> {
39+
/// let mut f = try!(File::open("log.txt"));
40+
/// let mut reader = BufReader::new(f);
41+
///
42+
/// let mut line = String::new();
43+
/// let len = try!(reader.read_line(&mut line));
44+
/// println!("First line is {} bytes long", len);
45+
/// # Ok(())
46+
/// # }
47+
/// ```
3048
#[stable(feature = "rust1", since = "1.0.0")]
3149
pub struct BufReader<R> {
3250
inner: R,

src/libstd/io/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -506,11 +506,14 @@ fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
506506
}
507507
}
508508

509-
/// A Buffer is a type of reader which has some form of internal buffering to
509+
/// A `BufRead` is a type of reader which has some form of internal buffering to
510510
/// allow certain kinds of reading operations to be more optimized than others.
511511
///
512512
/// This type extends the `Read` trait with a few methods that are not
513513
/// possible to reasonably implement with purely a read interface.
514+
///
515+
/// You can use the [`BufReader` wrapper type](struct.BufReader.html) to turn any
516+
/// reader into a buffered reader.
514517
#[stable(feature = "rust1", since = "1.0.0")]
515518
pub trait BufRead: Read {
516519
/// Fills the internal buffer of this object, returning the buffer contents.

0 commit comments

Comments
 (0)