]> git.lizzy.rs Git - rust.git/commit
Back io::stdin with a global singleton BufferedReader
authorSteven Fackler <sfackler@gmail.com>
Sun, 30 Nov 2014 07:07:43 +0000 (23:07 -0800)
committerSteven Fackler <sfackler@gmail.com>
Thu, 4 Dec 2014 07:18:52 +0000 (23:18 -0800)
commite7c1f57d6c8781cfb3e746eac5f13f760fcde2b4
tree3865b4c74acc3211f6144c8dd7496820b354a1b9
parentf33d879a7094bce7e16345dcc2efa85da6f05261
Back io::stdin with a global singleton BufferedReader

io::stdin returns a new `BufferedReader` each time it's called, which
results in some very confusing behavior with disappearing output. It now
returns a `StdinReader`, which wraps a global singleton
`Arc<Mutex<BufferedReader<StdReader>>`. `Reader` is implemented directly
on `StdinReader`. However, `Buffer` is not, as the `fill_buf` method is
fundamentaly un-thread safe. A `lock` method is defined on `StdinReader`
which returns a smart pointer wrapping the underlying `BufferedReader`
while guaranteeing mutual exclusion.

Code that treats the return value of io::stdin as implementing `Buffer`
will break. Add a call to `lock`:

```rust
io::stdin().lines()
// =>
io::stdin().lock().lines()
```

Closes #14434

[breaking-change]
src/libstd/io/mod.rs
src/libstd/io/stdio.rs
src/test/bench/shootout-k-nucleotide.rs
src/test/bench/sudoku.rs
src/test/compile-fail/cannot-mutate-captured-non-mut-var.rs
src/test/run-pass/issue-13304.rs
src/test/run-pass/issue-14456.rs
src/test/run-pass/issue-16671.rs