Remove result type from raw standard streams constructors
Raw standard streams constructors are infallible. Remove unnecessary result type.
This commit is contained in:
parent
32cb8d40eb
commit
479c23bb49
@ -50,8 +50,8 @@ struct StderrRaw(stdio::Stderr);
|
||||
/// handles is **not** available to raw handles returned from this function.
|
||||
///
|
||||
/// The returned handle has no external synchronization or buffering.
|
||||
fn stdin_raw() -> io::Result<StdinRaw> {
|
||||
stdio::Stdin::new().map(StdinRaw)
|
||||
fn stdin_raw() -> StdinRaw {
|
||||
StdinRaw(stdio::Stdin::new())
|
||||
}
|
||||
|
||||
/// Constructs a new raw handle to the standard output stream of this process.
|
||||
@ -63,8 +63,8 @@ fn stdin_raw() -> io::Result<StdinRaw> {
|
||||
///
|
||||
/// The returned handle has no external synchronization or buffering layered on
|
||||
/// top.
|
||||
fn stdout_raw() -> io::Result<StdoutRaw> {
|
||||
stdio::Stdout::new().map(StdoutRaw)
|
||||
fn stdout_raw() -> StdoutRaw {
|
||||
StdoutRaw(stdio::Stdout::new())
|
||||
}
|
||||
|
||||
/// Constructs a new raw handle to the standard error stream of this process.
|
||||
@ -74,8 +74,8 @@ fn stdout_raw() -> io::Result<StdoutRaw> {
|
||||
///
|
||||
/// The returned handle has no external synchronization or buffering layered on
|
||||
/// top.
|
||||
fn stderr_raw() -> io::Result<StderrRaw> {
|
||||
stdio::Stderr::new().map(StderrRaw)
|
||||
fn stderr_raw() -> StderrRaw {
|
||||
StderrRaw(stdio::Stderr::new())
|
||||
}
|
||||
|
||||
impl Read for StdinRaw {
|
||||
@ -356,11 +356,7 @@ pub fn stdin() -> Stdin {
|
||||
|
||||
fn stdin_init() -> Arc<Mutex<BufReader<Maybe<StdinRaw>>>> {
|
||||
// This must not reentrantly access `INSTANCE`
|
||||
let stdin = match stdin_raw() {
|
||||
Ok(stdin) => Maybe::Real(stdin),
|
||||
_ => Maybe::Fake,
|
||||
};
|
||||
|
||||
let stdin = Maybe::Real(stdin_raw());
|
||||
Arc::new(Mutex::new(BufReader::with_capacity(stdio::STDIN_BUF_SIZE, stdin)))
|
||||
}
|
||||
}
|
||||
@ -602,10 +598,7 @@ pub fn stdout() -> Stdout {
|
||||
|
||||
fn stdout_init() -> Arc<ReentrantMutex<RefCell<LineWriter<Maybe<StdoutRaw>>>>> {
|
||||
// This must not reentrantly access `INSTANCE`
|
||||
let stdout = match stdout_raw() {
|
||||
Ok(stdout) => Maybe::Real(stdout),
|
||||
_ => Maybe::Fake,
|
||||
};
|
||||
let stdout = Maybe::Real(stdout_raw());
|
||||
unsafe {
|
||||
let ret = Arc::new(ReentrantMutex::new(RefCell::new(LineWriter::new(stdout))));
|
||||
ret.init();
|
||||
@ -788,9 +781,8 @@ pub fn stderr() -> Stderr {
|
||||
static INIT: Once = Once::new();
|
||||
INIT.call_once(|| unsafe {
|
||||
INSTANCE.init();
|
||||
if let Ok(stderr) = stderr_raw() {
|
||||
*INSTANCE.lock().borrow_mut() = Maybe::Real(stderr);
|
||||
}
|
||||
let stderr = stderr_raw();
|
||||
*INSTANCE.lock().borrow_mut() = Maybe::Real(stderr);
|
||||
});
|
||||
Stderr { inner: &INSTANCE }
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ pub struct Stdout(());
|
||||
pub struct Stderr(());
|
||||
|
||||
impl Stdin {
|
||||
pub fn new() -> io::Result<Stdin> {
|
||||
Ok(Stdin(()))
|
||||
pub fn new() -> Stdin {
|
||||
Stdin(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,8 +18,8 @@ impl io::Read for Stdin {
|
||||
}
|
||||
|
||||
impl Stdout {
|
||||
pub fn new() -> io::Result<Stdout> {
|
||||
Ok(Stdout(()))
|
||||
pub fn new() -> Stdout {
|
||||
Stdout(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,8 +37,8 @@ impl io::Write for Stdout {
|
||||
}
|
||||
|
||||
impl Stderr {
|
||||
pub fn new() -> io::Result<Stderr> {
|
||||
Ok(Stderr(()))
|
||||
pub fn new() -> Stderr {
|
||||
Stderr(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,5 +62,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
|
||||
pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
|
||||
|
||||
pub fn panic_output() -> Option<impl io::Write> {
|
||||
Stderr::new().ok()
|
||||
Some(Stderr::new())
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ pub struct Stdout;
|
||||
pub struct Stderr;
|
||||
|
||||
impl Stdin {
|
||||
pub fn new() -> io::Result<Stdin> {
|
||||
Ok(Stdin)
|
||||
pub fn new() -> Stdin {
|
||||
Stdin
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,8 +28,8 @@ impl io::Read for Stdin {
|
||||
}
|
||||
|
||||
impl Stdout {
|
||||
pub fn new() -> io::Result<Stdout> {
|
||||
Ok(Stdout)
|
||||
pub fn new() -> Stdout {
|
||||
Stdout
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,8 +69,8 @@ impl io::Write for Stdout {
|
||||
}
|
||||
|
||||
impl Stderr {
|
||||
pub fn new() -> io::Result<Stderr> {
|
||||
Ok(Stderr)
|
||||
pub fn new() -> Stderr {
|
||||
Stderr
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,5 +116,5 @@ pub fn is_ebadf(_err: &io::Error) -> bool {
|
||||
}
|
||||
|
||||
pub fn panic_output() -> Option<impl io::Write> {
|
||||
Stderr::new().ok()
|
||||
Some(Stderr::new())
|
||||
}
|
||||
|
@ -19,8 +19,8 @@ fn with_std_fd<F: FnOnce(&FileDesc) -> R, R>(fd: abi::Fd, f: F) -> R {
|
||||
}
|
||||
|
||||
impl Stdin {
|
||||
pub fn new() -> io::Result<Stdin> {
|
||||
Ok(Stdin(()))
|
||||
pub fn new() -> Stdin {
|
||||
Stdin(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,8 +31,8 @@ impl io::Read for Stdin {
|
||||
}
|
||||
|
||||
impl Stdout {
|
||||
pub fn new() -> io::Result<Stdout> {
|
||||
Ok(Stdout(()))
|
||||
pub fn new() -> Stdout {
|
||||
Stdout(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,8 +47,8 @@ impl io::Write for Stdout {
|
||||
}
|
||||
|
||||
impl Stderr {
|
||||
pub fn new() -> io::Result<Stderr> {
|
||||
Ok(Stderr(()))
|
||||
pub fn new() -> Stderr {
|
||||
Stderr(())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,8 @@ pub struct Stdout(());
|
||||
pub struct Stderr(());
|
||||
|
||||
impl Stdin {
|
||||
pub fn new() -> io::Result<Stdin> {
|
||||
Ok(Stdin(()))
|
||||
pub fn new() -> Stdin {
|
||||
Stdin(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,8 +28,8 @@ impl io::Read for Stdin {
|
||||
}
|
||||
|
||||
impl Stdout {
|
||||
pub fn new() -> io::Result<Stdout> {
|
||||
Ok(Stdout(()))
|
||||
pub fn new() -> Stdout {
|
||||
Stdout(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,8 +53,8 @@ impl io::Write for Stdout {
|
||||
}
|
||||
|
||||
impl Stderr {
|
||||
pub fn new() -> io::Result<Stderr> {
|
||||
Ok(Stderr(()))
|
||||
pub fn new() -> Stderr {
|
||||
Stderr(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,5 +84,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
|
||||
pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
|
||||
|
||||
pub fn panic_output() -> Option<impl io::Write> {
|
||||
Stderr::new().ok()
|
||||
Some(Stderr::new())
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ pub struct Stdout;
|
||||
pub struct Stderr;
|
||||
|
||||
impl Stdin {
|
||||
pub fn new() -> io::Result<Stdin> {
|
||||
Ok(Stdin)
|
||||
pub fn new() -> Stdin {
|
||||
Stdin
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,8 +17,8 @@ impl io::Read for Stdin {
|
||||
}
|
||||
|
||||
impl Stdout {
|
||||
pub fn new() -> io::Result<Stdout> {
|
||||
Ok(Stdout)
|
||||
pub fn new() -> Stdout {
|
||||
Stdout
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,8 +33,8 @@ impl io::Write for Stdout {
|
||||
}
|
||||
|
||||
impl Stderr {
|
||||
pub fn new() -> io::Result<Stderr> {
|
||||
Ok(Stderr)
|
||||
pub fn new() -> Stderr {
|
||||
Stderr
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,8 +6,8 @@ pub struct Stdout(());
|
||||
pub struct Stderr(());
|
||||
|
||||
impl Stdin {
|
||||
pub fn new() -> io::Result<Stdin> {
|
||||
Ok(Stdin(()))
|
||||
pub fn new() -> Stdin {
|
||||
Stdin(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,8 +21,8 @@ impl io::Read for Stdin {
|
||||
}
|
||||
|
||||
impl Stdout {
|
||||
pub fn new() -> io::Result<Stdout> {
|
||||
Ok(Stdout(()))
|
||||
pub fn new() -> Stdout {
|
||||
Stdout(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,8 +40,8 @@ impl io::Write for Stdout {
|
||||
}
|
||||
|
||||
impl Stderr {
|
||||
pub fn new() -> io::Result<Stderr> {
|
||||
Ok(Stderr(()))
|
||||
pub fn new() -> Stderr {
|
||||
Stderr(())
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,5 +65,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
|
||||
pub const STDIN_BUF_SIZE: usize = crate::sys_common::io::DEFAULT_BUF_SIZE;
|
||||
|
||||
pub fn panic_output() -> Option<impl io::Write> {
|
||||
Stderr::new().ok()
|
||||
Some(Stderr::new())
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ pub struct Stdout;
|
||||
pub struct Stderr;
|
||||
|
||||
impl Stdin {
|
||||
pub fn new() -> io::Result<Stdin> {
|
||||
Ok(Stdin)
|
||||
pub fn new() -> Stdin {
|
||||
Stdin
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -33,8 +33,8 @@ impl io::Read for Stdin {
|
||||
}
|
||||
|
||||
impl Stdout {
|
||||
pub fn new() -> io::Result<Stdout> {
|
||||
Ok(Stdout)
|
||||
pub fn new() -> Stdout {
|
||||
Stdout
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -62,8 +62,8 @@ impl io::Write for Stdout {
|
||||
}
|
||||
|
||||
impl Stderr {
|
||||
pub fn new() -> io::Result<Stderr> {
|
||||
Ok(Stderr)
|
||||
pub fn new() -> Stderr {
|
||||
Stderr
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -98,5 +98,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
|
||||
}
|
||||
|
||||
pub fn panic_output() -> Option<impl io::Write> {
|
||||
Stderr::new().ok()
|
||||
Some(Stderr::new())
|
||||
}
|
||||
|
@ -131,8 +131,8 @@ fn write_u16s(handle: c::HANDLE, data: &[u16]) -> io::Result<usize> {
|
||||
}
|
||||
|
||||
impl Stdin {
|
||||
pub fn new() -> io::Result<Stdin> {
|
||||
Ok(Stdin { surrogate: 0 })
|
||||
pub fn new() -> Stdin {
|
||||
Stdin { surrogate: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
@ -255,8 +255,8 @@ fn utf16_to_utf8(utf16: &[u16], utf8: &mut [u8]) -> io::Result<usize> {
|
||||
}
|
||||
|
||||
impl Stdout {
|
||||
pub fn new() -> io::Result<Stdout> {
|
||||
Ok(Stdout)
|
||||
pub fn new() -> Stdout {
|
||||
Stdout
|
||||
}
|
||||
}
|
||||
|
||||
@ -271,8 +271,8 @@ impl io::Write for Stdout {
|
||||
}
|
||||
|
||||
impl Stderr {
|
||||
pub fn new() -> io::Result<Stderr> {
|
||||
Ok(Stderr)
|
||||
pub fn new() -> Stderr {
|
||||
Stderr
|
||||
}
|
||||
}
|
||||
|
||||
@ -291,5 +291,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
|
||||
}
|
||||
|
||||
pub fn panic_output() -> Option<impl io::Write> {
|
||||
Stderr::new().ok()
|
||||
Some(Stderr::new())
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ fn write(handle_id: c::DWORD, data: &[u8]) -> io::Result<usize> {
|
||||
}
|
||||
|
||||
impl Stdin {
|
||||
pub fn new() -> io::Result<Stdin> {
|
||||
Ok(Stdin {})
|
||||
pub fn new() -> Stdin {
|
||||
Stdin {}
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,8 +44,8 @@ impl io::Read for Stdin {
|
||||
}
|
||||
|
||||
impl Stdout {
|
||||
pub fn new() -> io::Result<Stdout> {
|
||||
Ok(Stdout)
|
||||
pub fn new() -> Stdout {
|
||||
Stdout
|
||||
}
|
||||
}
|
||||
|
||||
@ -60,8 +60,8 @@ impl io::Write for Stdout {
|
||||
}
|
||||
|
||||
impl Stderr {
|
||||
pub fn new() -> io::Result<Stderr> {
|
||||
Ok(Stderr)
|
||||
pub fn new() -> Stderr {
|
||||
Stderr
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,5 +80,5 @@ pub fn is_ebadf(err: &io::Error) -> bool {
|
||||
}
|
||||
|
||||
pub fn panic_output() -> Option<impl io::Write> {
|
||||
Stderr::new().ok()
|
||||
Some(Stderr::new())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user