Skip to content
New issue

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

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

Already on GitHub? # to your account

Added io forwarding methods to the stdio structs #72705

Merged
merged 3 commits into from
Jun 28, 2020
Merged
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
77 changes: 77 additions & 0 deletions src/libstd/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,20 @@ impl Read for StdinRaw {
unsafe fn initializer(&self) -> Initializer {
Initializer::nop()
}

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
self.0.read_to_end(buf)
}

fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
self.0.read_to_string(buf)
}

fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
self.0.read_exact(buf)
}
}

impl Write for StdoutRaw {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.write(buf)
Expand All @@ -114,7 +127,20 @@ impl Write for StdoutRaw {
fn flush(&mut self) -> io::Result<()> {
self.0.flush()
}

fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
self.0.write_all(buf)
}

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
self.0.write_all_vectored(bufs)
}

fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
self.0.write_fmt(fmt)
}
}

impl Write for StderrRaw {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.write(buf)
Expand All @@ -132,6 +158,18 @@ impl Write for StderrRaw {
fn flush(&mut self) -> io::Result<()> {
self.0.flush()
}

fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
self.0.write_all(buf)
}

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
self.0.write_all_vectored(bufs)
}

fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
self.0.write_fmt(fmt)
}
}

enum Maybe<T> {
Expand Down Expand Up @@ -420,16 +458,37 @@ impl Read for StdinLock<'_> {
unsafe fn initializer(&self) -> Initializer {
Initializer::nop()
}

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
self.inner.read_to_end(buf)
}

fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
self.inner.read_to_string(buf)
}

fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
self.inner.read_exact(buf)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl BufRead for StdinLock<'_> {
fn fill_buf(&mut self) -> io::Result<&[u8]> {
self.inner.fill_buf()
}

fn consume(&mut self, n: usize) {
self.inner.consume(n)
}

fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> io::Result<usize> {
self.inner.read_until(byte, buf)
}

fn read_line(&mut self, buf: &mut String) -> io::Result<usize> {
self.inner.read_line(buf)
}
}

#[stable(feature = "std_debug", since = "1.16.0")]
Expand Down Expand Up @@ -593,6 +652,9 @@ impl Write for Stdout {
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
self.lock().write_all(buf)
}
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
self.lock().write_all_vectored(bufs)
}
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> io::Result<()> {
self.lock().write_fmt(args)
}
Expand All @@ -612,6 +674,12 @@ impl Write for StdoutLock<'_> {
fn flush(&mut self) -> io::Result<()> {
self.inner.borrow_mut().flush()
}
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
self.inner.borrow_mut().write_all(buf)
}
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
self.inner.borrow_mut().write_all_vectored(bufs)
}
}

#[stable(feature = "std_debug", since = "1.16.0")]
Expand Down Expand Up @@ -767,6 +835,9 @@ impl Write for Stderr {
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
self.lock().write_all(buf)
}
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
self.lock().write_all_vectored(bufs)
}
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> io::Result<()> {
self.lock().write_fmt(args)
}
Expand All @@ -786,6 +857,12 @@ impl Write for StderrLock<'_> {
fn flush(&mut self) -> io::Result<()> {
self.inner.borrow_mut().flush()
}
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
self.inner.borrow_mut().write_all(buf)
}
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
self.inner.borrow_mut().write_all_vectored(bufs)
}
}

#[stable(feature = "std_debug", since = "1.16.0")]
Expand Down