Skip to content

Commit 358dc1d

Browse files
committed
Added io forwarding methods to the stdio structs
1 parent 4512721 commit 358dc1d

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

src/libstd/io/stdio.rs

+83
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,20 @@ impl Read for StdinRaw {
9696
unsafe fn initializer(&self) -> Initializer {
9797
Initializer::nop()
9898
}
99+
100+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
101+
self.0.read_to_end(buf)
102+
}
103+
104+
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
105+
self.0.read_to_string(buf)
106+
}
107+
108+
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
109+
self.0.read_exact(buf)
110+
}
99111
}
112+
100113
impl Write for StdoutRaw {
101114
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
102115
self.0.write(buf)
@@ -114,7 +127,20 @@ impl Write for StdoutRaw {
114127
fn flush(&mut self) -> io::Result<()> {
115128
self.0.flush()
116129
}
130+
131+
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
132+
self.0.write_all(buf)
133+
}
134+
135+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
136+
self.0.write_all_vectored(bufs)
137+
}
138+
139+
fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
140+
self.0.write_fmt(fmt)
141+
}
117142
}
143+
118144
impl Write for StderrRaw {
119145
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
120146
self.0.write(buf)
@@ -132,6 +158,18 @@ impl Write for StderrRaw {
132158
fn flush(&mut self) -> io::Result<()> {
133159
self.0.flush()
134160
}
161+
162+
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
163+
self.0.write_all(buf)
164+
}
165+
166+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
167+
self.0.write_all_vectored(bufs)
168+
}
169+
170+
fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
171+
self.0.write_fmt(fmt)
172+
}
135173
}
136174

137175
enum Maybe<T> {
@@ -420,16 +458,37 @@ impl Read for StdinLock<'_> {
420458
unsafe fn initializer(&self) -> Initializer {
421459
Initializer::nop()
422460
}
461+
462+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
463+
self.inner.read_to_end(buf)
464+
}
465+
466+
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
467+
self.inner.read_to_string(buf)
468+
}
469+
470+
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
471+
self.inner.read_exact(buf)
472+
}
423473
}
424474

425475
#[stable(feature = "rust1", since = "1.0.0")]
426476
impl BufRead for StdinLock<'_> {
427477
fn fill_buf(&mut self) -> io::Result<&[u8]> {
428478
self.inner.fill_buf()
429479
}
480+
430481
fn consume(&mut self, n: usize) {
431482
self.inner.consume(n)
432483
}
484+
485+
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> io::Result<usize> {
486+
self.inner.read_until(byte, buf)
487+
}
488+
489+
fn read_line(&mut self, buf: &mut String) -> io::Result<usize> {
490+
self.inner.read_line(buf)
491+
}
433492
}
434493

435494
#[stable(feature = "std_debug", since = "1.16.0")]
@@ -596,6 +655,9 @@ impl Write for Stdout {
596655
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> io::Result<()> {
597656
self.lock().write_fmt(args)
598657
}
658+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
659+
self.lock().write_all_vectored(bufs)
660+
}
599661
}
600662
#[stable(feature = "rust1", since = "1.0.0")]
601663
impl Write for StdoutLock<'_> {
@@ -612,6 +674,15 @@ impl Write for StdoutLock<'_> {
612674
fn flush(&mut self) -> io::Result<()> {
613675
self.inner.borrow_mut().flush()
614676
}
677+
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
678+
self.inner.borrow_mut().write_all(buf)
679+
}
680+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
681+
self.inner.borrow_mut().write_all_vectored(bufs)
682+
}
683+
fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
684+
self.inner.borrow_mut().write_fmt(fmt)
685+
}
615686
}
616687

617688
#[stable(feature = "std_debug", since = "1.16.0")]
@@ -770,6 +841,9 @@ impl Write for Stderr {
770841
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> io::Result<()> {
771842
self.lock().write_fmt(args)
772843
}
844+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
845+
self.lock().write_all_vectored(bufs)
846+
}
773847
}
774848
#[stable(feature = "rust1", since = "1.0.0")]
775849
impl Write for StderrLock<'_> {
@@ -786,6 +860,15 @@ impl Write for StderrLock<'_> {
786860
fn flush(&mut self) -> io::Result<()> {
787861
self.inner.borrow_mut().flush()
788862
}
863+
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
864+
self.inner.borrow_mut().write_all(buf)
865+
}
866+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
867+
self.inner.borrow_mut().write_all_vectored(bufs)
868+
}
869+
fn write_fmt(&mut self, fmt: fmt::Arguments<'_>) -> io::Result<()> {
870+
self.inner.borrow_mut().write_fmt(fmt)
871+
}
789872
}
790873

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

0 commit comments

Comments
 (0)