Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a buffered stdin by default. #12422

Merged
merged 1 commit into from
Feb 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
```
Expand Down Expand Up @@ -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");
/// ```
///
Expand Down
19 changes: 16 additions & 3 deletions src/libstd/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ out.write(bytes!("Hello, world!"));
use container::Container;
use fmt;
use io::{Reader, Writer, IoResult, IoError, OtherIoError,
standard_error, EndOfFile, LineBufferedWriter};
standard_error, EndOfFile, LineBufferedWriter, BufferedReader};
use libc;
use mem::replace;
use option::{Option, Some, None};
Expand Down Expand Up @@ -86,8 +86,21 @@ fn src<T>(fd: libc::c_int, readable: bool, f: |StdSource| -> T) -> T {

/// Creates a new non-blocking handle to the stdin of the current process.
///
/// See `stdout()` for notes about this function.
pub fn stdin() -> StdReader {
/// The returned handled is buffered by default with a `BufferedReader`. If
/// buffered access is not desired, the `stdin_raw` function is provided to
/// provided unbuffered access to stdin.
///
/// See `stdout()` for more notes about this function.
pub fn stdin() -> BufferedReader<StdReader> {
BufferedReader::new(stdin_raw())
}

/// Creates a new non-blocking handle to the stdin of the current process.
///
/// Unlike `stdin()`, the returned reader is *not* a buffered reader.
///
/// See `stdout()` for more notes about this function.
pub fn stdin_raw() -> StdReader {
src(libc::STDIN_FILENO, true, |src| StdReader { inner: src })
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/sudoku.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ fn main() {
let mut sudoku = if use_default {
Sudoku::from_vec(&DEFAULT_SUDOKU)
} else {
Sudoku::read(BufferedReader::new(io::stdin()))
Sudoku::read(io::stdin())
};
sudoku.solve();
sudoku.write(&mut io::stdout());
Expand Down