Add example code and cross-link to BufReader docs
This commit is contained in:
parent
9c47ebb00a
commit
d776191d4a
2 changed files with 22 additions and 1 deletions
|
@ -27,6 +27,24 @@ use iter;
|
||||||
/// For example, every call to `read` on `TcpStream` results in a system call.
|
/// For example, every call to `read` on `TcpStream` results in a system call.
|
||||||
/// A `BufReader` performs large, infrequent reads on the underlying `Read`
|
/// A `BufReader` performs large, infrequent reads on the underlying `Read`
|
||||||
/// and maintains an in-memory buffer of the results.
|
/// 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")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct BufReader<R> {
|
pub struct BufReader<R> {
|
||||||
inner: R,
|
inner: R,
|
||||||
|
|
|
@ -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.
|
/// 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
|
/// This type extends the `Read` trait with a few methods that are not
|
||||||
/// possible to reasonably implement with purely a read interface.
|
/// 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")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub trait BufRead: Read {
|
pub trait BufRead: Read {
|
||||||
/// Fills the internal buffer of this object, returning the buffer contents.
|
/// Fills the internal buffer of this object, returning the buffer contents.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue