-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
std: Implement stdio for std::io
#22797
Conversation
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
Note that this PR is not intended to be the final result of these functions. This will likely land ahead of the RFC but only because it facilitates migration to r? @aturon API-wise |
Ah I will try to add some tests soon as well. I'll both add some independent ones as well as migrate some existing run-pass/bench tests to this API. |
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { | ||
self.inner.write(&buf[..cmp::min(buf.len(), OUT_MAX)]) | ||
} | ||
fn flush(&mut self) -> io::Result<()> { Ok(()) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe you should just go ahead and do self.inner.flush()
here, even if the inner returns Ok(())
anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inner
doesn't actually implement flush
in this case. Each of the underlying primitives implement write
as an inherent method (taking &self
) so there's no flush
method to call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does implement it at https://github.com/rust-lang/rust/pull/22797/files#diff-c7c55a739480d5cc82ecd059127d62a9R78. I just generally prefer seeing wrapper structures like StderrLock
not assume anything about the object it wraps and just pass the responsibility of doing what’s right to the object it wraps over.
Anyway that’s just a nit and general style preference, so you’re free to ignore it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gah sorry, was thinking of the wrong thing, I will definitely delegate!
I’ve finished my pass over it 😉 |
API looks fine to me. I may want to make a few tweaks but we can work this out on the RFC. Thanks @alexcrichton! |
e5580c7
to
8fa751d
Compare
I've pushed an update that removes all I have also now updated with some usage in tests as well (and will add some more over time as well). |
8fa751d
to
5c0ed68
Compare
@bors: r+ 5c0ed68 |
5c0ed68
to
1c32ac7
Compare
@bors: r=aturon 1c32ac7 |
⌛ Testing commit 1c32ac7 with merge a8b753b... |
💔 Test failed - auto-mac-32-opt |
@bors: retry |
⌛ Testing commit 1c32ac7 with merge be1f11a... |
💔 Test failed - auto-win-32-nopt-t |
03e97a8
to
c1854a8
Compare
This is an implementation of RFC 899 and adds stdio functionality to the new `std::io` module. Details of the API can be found on the RFC, but from a high level: * `io::{stdin, stdout, stderr}` constructors are now available. There are also `*_raw` variants for unbuffered and unlocked access. * All handles are globally shared (excluding raw variants). * The stderr handle is no longer buffered. * All handles can be explicitly locked (excluding the raw variants). The `print!` and `println!` machinery has not yet been hooked up to these streams just yet. The `std::fmt::output` module has also not yet been implemented as part of this commit.
This is an implementation of RFC 899 and adds stdio functionality to the new `std::io` module. Details of the API can be found on the RFC, but from a high level: * `io::{stdin, stdout, stderr}` constructors are now available. There are also `*_raw` variants for unbuffered and unlocked access. * All handles are globally shared (excluding raw variants). * The stderr handle is no longer buffered. * All handles can be explicitly locked (excluding the raw variants). The `print!` and `println!` machinery has not yet been hooked up to these streams just yet. The `std::fmt::output` module has also not yet been implemented as part of this commit.
💔 Test failed - auto-linux-64-x-android-t |
@bors retry |
⚡ Previous build results are reusable. Rebuilding only auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-nopt-t, auto-linux-64-opt, auto-linux-64-x-android-t, auto-mac-32-opt, auto-mac-64-nopt-t, auto-mac-64-opt, auto-win-32-nopt-t, auto-win-32-opt, auto-win-64-nopt-t, auto-win-64-opt... |
💔 Test failed - auto-win-32-opt |
@bors retry |
⌛ Testing commit 94d71f8 with merge 13769d8... |
💔 Test failed - auto-linux-64-x-android-t |
@bors retry |
⚡ Previous build results are reusable. Rebuilding only auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-nopt-t, auto-linux-64-opt, auto-linux-64-x-android-t, auto-mac-32-opt, auto-mac-64-nopt-t, auto-mac-64-opt, auto-win-32-nopt-t, auto-win-32-opt, auto-win-64-nopt-t, auto-win-64-opt... |
💔 Test failed - auto-linux-64-x-android-t |
@bors: retry |
⚡ Previous build results are reusable. Rebuilding only auto-linux-32-nopt-t, auto-linux-32-opt, auto-linux-64-nopt-t, auto-linux-64-x-android-t, auto-mac-32-opt, auto-mac-64-nopt-t, auto-win-32-nopt-t, auto-win-32-opt, auto-win-64-nopt-t, auto-win-64-opt... |
💔 Test failed - auto-win-64-nopt-t |
Er, what? Second time I've seen that failure today. Looks deterministic. |
@bors retry |
This is an implementation of RFC 899 and adds stdio functionality to the new `std::io` module. Details of the API can be found on the RFC, but from a high level: * `io::{stdin, stdout, stderr}` constructors are now available. There are also `*_raw` variants for unbuffered and unlocked access. * All handles are globally shared (excluding raw variants). * The stderr handle is no longer buffered. * All handles can be explicitly locked (excluding the raw variants). The `print!` and `println!` machinery has not yet been hooked up to these streams just yet. The `std::fmt::output` module has also not yet been implemented as part of this commit.
This is an implementation of RFC 899 and adds stdio functionality to the new
std::io
module. Details of the API can be found on the RFC, but from a highlevel:
io::{stdin, stdout, stderr}
constructors are now available. There are also*_raw
variants for unbuffered and unlocked access.The
print!
andprintln!
machinery has not yet been hooked up to thesestreams just yet. The
std::fmt::output
module has also not yet beenimplemented as part of this commit.