Return a buffered stdin by default.

One of the most common ways to use the stdin stream is to read it line by line
for a small program. In order to facilitate this common usage pattern, this
commit changes the stdin() function to return a BufferedReader by default. A new
`stdin_raw()` method was added to get access to the raw unbuffered stream.

I have not changed the stdout or stderr methods because they are currently
unable to flush in their destructor, but #12403 should have just fixed that.
This commit is contained in:
Alex Crichton
2014-02-20 09:11:56 -08:00
parent 879e8aa7be
commit 7736985f78
3 changed files with 21 additions and 11 deletions

View File

@@ -26,11 +26,9 @@ Some examples of obvious things you might want to do
* Read lines from stdin
```rust
use std::io::BufferedReader;
use std::io::stdin;
use std::io;
let mut stdin = BufferedReader::new(stdin());
for line in stdin.lines() {
for line in io::stdin().lines() {
print!("{}", line);
}
```
@@ -1097,10 +1095,9 @@ pub trait Buffer: Reader {
/// # Example
///
/// ```rust
/// use std::io::{BufferedReader, stdin};
///
/// let mut reader = BufferedReader::new(stdin());
/// use std::io;
///
/// let mut reader = io::stdin();
/// let input = reader.read_line().ok().unwrap_or(~"nothing");
/// ```
///