about summary refs log tree commit diff
path: root/src/libstd/io
diff options
context:
space:
mode:
authorMatt Brubeck <mbrubeck@limpet.net>2015-05-19 09:49:04 -0700
committerMatt Brubeck <mbrubeck@limpet.net>2015-05-19 10:41:19 -0700
commitd776191d4a84dd13080b3efdb449e4c036eb3f7e (patch)
treecb3a713c67884b9d84de3b9a71c36dbd5f9301a9 /src/libstd/io
parent9c47ebb00abecf2b2fe7fa0b0ea059c8327b40f2 (diff)
downloadrust-d776191d4a84dd13080b3efdb449e4c036eb3f7e.tar.gz
rust-d776191d4a84dd13080b3efdb449e4c036eb3f7e.zip
Add example code and cross-link to BufReader docs
Diffstat (limited to 'src/libstd/io')
-rw-r--r--src/libstd/io/buffered.rs18
-rw-r--r--src/libstd/io/mod.rs5
2 files changed, 22 insertions, 1 deletions
diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs
index 43a26292618..c355be9bc78 100644
--- a/src/libstd/io/buffered.rs
+++ b/src/libstd/io/buffered.rs
@@ -27,6 +27,24 @@ use iter;
 /// For example, every call to `read` on `TcpStream` results in a system call.
 /// A `BufReader` performs large, infrequent reads on the underlying `Read`
 /// and maintains an in-memory buffer of the results.
+///
+/// # Examples
+///
+/// ```no_run
+/// use std::io::prelude::*;
+/// use std::io::BufReader;
+/// use std::fs::File;
+///
+/// # fn foo() -> std::io::Result<()> {
+/// let mut f = try!(File::open("log.txt"));
+/// let mut reader = BufReader::new(f);
+///
+/// let mut line = String::new();
+/// let len = try!(reader.read_line(&mut line));
+/// println!("First line is {} bytes long", len);
+/// # Ok(())
+/// # }
+/// ```
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct BufReader<R> {
     inner: R,
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index e7b2b01d09f..72a3a75d422 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -506,11 +506,14 @@ fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
     }
 }
 
-/// A Buffer is a type of reader which has some form of internal buffering to
+/// A `BufRead` is a type of reader which has some form of internal buffering to
 /// allow certain kinds of reading operations to be more optimized than others.
 ///
 /// This type extends the `Read` trait with a few methods that are not
 /// possible to reasonably implement with purely a read interface.
+///
+/// You can use the [`BufReader` wrapper type](struct.BufReader.html) to turn any
+/// reader into a buffered reader.
 #[stable(feature = "rust1", since = "1.0.0")]
 pub trait BufRead: Read {
     /// Fills the internal buffer of this object, returning the buffer contents.