Skip to content

Commit 28db521

Browse files
author
Federico Ponzi
committed
More implementations of Write for immutable refs
Fixes #73836
1 parent fe8ab8a commit 28db521

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

library/std/src/io/stdio.rs

+54
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,33 @@ impl Write for Stdout {
606606
self.lock().write_fmt(args)
607607
}
608608
}
609+
610+
#[stable(feature = "write_mt", since = "1.47.0")]
611+
impl Write for &Stdout {
612+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
613+
self.lock().write(buf)
614+
}
615+
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
616+
self.lock().write_vectored(bufs)
617+
}
618+
#[inline]
619+
fn is_write_vectored(&self) -> bool {
620+
self.lock().is_write_vectored()
621+
}
622+
fn flush(&mut self) -> io::Result<()> {
623+
self.lock().flush()
624+
}
625+
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
626+
self.lock().write_all(buf)
627+
}
628+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
629+
self.lock().write_all_vectored(bufs)
630+
}
631+
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> io::Result<()> {
632+
self.lock().write_fmt(args)
633+
}
634+
}
635+
609636
#[stable(feature = "rust1", since = "1.0.0")]
610637
impl Write for StdoutLock<'_> {
611638
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
@@ -782,6 +809,33 @@ impl Write for Stderr {
782809
self.lock().write_fmt(args)
783810
}
784811
}
812+
813+
#[stable(feature = "write_mt", since = "1.47.0")]
814+
impl Write for &Stderr {
815+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
816+
self.lock().write(buf)
817+
}
818+
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
819+
self.lock().write_vectored(bufs)
820+
}
821+
#[inline]
822+
fn is_write_vectored(&self) -> bool {
823+
self.lock().is_write_vectored()
824+
}
825+
fn flush(&mut self) -> io::Result<()> {
826+
self.lock().flush()
827+
}
828+
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
829+
self.lock().write_all(buf)
830+
}
831+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
832+
self.lock().write_all_vectored(bufs)
833+
}
834+
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> io::Result<()> {
835+
self.lock().write_fmt(args)
836+
}
837+
}
838+
785839
#[stable(feature = "rust1", since = "1.0.0")]
786840
impl Write for StderrLock<'_> {
787841
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {

library/std/src/io/util.rs

+24
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,30 @@ impl Write for Sink {
248248
}
249249
}
250250

251+
#[stable(feature = "write_mt", since = "1.47.0")]
252+
impl Write for &Sink {
253+
#[inline]
254+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
255+
Ok(buf.len())
256+
}
257+
258+
#[inline]
259+
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
260+
let total_len = bufs.iter().map(|b| b.len()).sum();
261+
Ok(total_len)
262+
}
263+
264+
#[inline]
265+
fn is_write_vectored(&self) -> bool {
266+
true
267+
}
268+
269+
#[inline]
270+
fn flush(&mut self) -> io::Result<()> {
271+
Ok(())
272+
}
273+
}
274+
251275
#[stable(feature = "std_debug", since = "1.16.0")]
252276
impl fmt::Debug for Sink {
253277
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

library/std/src/process.rs

+19
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,25 @@ impl Write for ChildStdin {
262262
}
263263
}
264264

265+
#[stable(feature = "write_mt", since = "1.47.0")]
266+
impl Write for &ChildStdin {
267+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
268+
self.inner.write(buf)
269+
}
270+
271+
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
272+
self.inner.write_vectored(bufs)
273+
}
274+
275+
fn is_write_vectored(&self) -> bool {
276+
self.inner.is_write_vectored()
277+
}
278+
279+
fn flush(&mut self) -> io::Result<()> {
280+
Ok(())
281+
}
282+
}
283+
265284
impl AsInner<AnonPipe> for ChildStdin {
266285
fn as_inner(&self) -> &AnonPipe {
267286
&self.inner

0 commit comments

Comments
 (0)