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

Conversation

alexcrichton
Copy link
Member

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.

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 rust-lang#12403 should have just fixed that.
@lilyball
Copy link
Contributor

Hooray!

@DaGenix
Copy link

DaGenix commented Feb 21, 2014

Doesn't this mean that

let line1 = io::stdin().read_line();
let line2 = io::stdin().read_line();

is going to have surprising results? Unless I'm missing something, it seems like this change means that io::stdin() can never be called more than once by a program, although the docs don't mention such a limitation.

@lilyball
Copy link
Contributor

I think the next step is to make std::io::stdin() return a task-local reader. That still won't help with reading stdin from two separate tasks, but if you're doing that you're going to have issues anyway.

bors added a commit that referenced this pull request Feb 22, 2014
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.
@bors bors closed this Feb 22, 2014
@bors bors merged commit 7736985 into rust-lang:master Feb 22, 2014
@alexcrichton alexcrichton deleted the buffered-default branch February 22, 2014 19:12
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Mar 1, 2014
Similarly to rust-lang#12422 which made stdin buffered by default, this commit makes the
output streams also buffered by default. Now that buffered writers will flush
their contents when they are dropped, I don't believe that there's no reason why
the output shouldn't be buffered by default, which is what you want in 90% of
cases.

As with stdin, there are new stdout_raw() and stderr_raw() functions to get
unbuffered streams to stdout/stderr.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants