Skip to content

Commit 65bdf79

Browse files
Rollup merge of #76275 - FedericoPonzi:immutable-write-impl-73836, r=dtolnay
Implementation of Write for some immutable ref structs Fixes #73836
2 parents 4f3697b + 0acb0ed commit 65bdf79

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
@@ -586,6 +586,32 @@ impl fmt::Debug for Stdout {
586586

587587
#[stable(feature = "rust1", since = "1.0.0")]
588588
impl Write for Stdout {
589+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
590+
(&*self).write(buf)
591+
}
592+
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
593+
(&*self).write_vectored(bufs)
594+
}
595+
#[inline]
596+
fn is_write_vectored(&self) -> bool {
597+
io::Write::is_write_vectored(&&*self)
598+
}
599+
fn flush(&mut self) -> io::Result<()> {
600+
(&*self).flush()
601+
}
602+
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
603+
(&*self).write_all(buf)
604+
}
605+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
606+
(&*self).write_all_vectored(bufs)
607+
}
608+
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> io::Result<()> {
609+
(&*self).write_fmt(args)
610+
}
611+
}
612+
613+
#[stable(feature = "write_mt", since = "1.48.0")]
614+
impl Write for &Stdout {
589615
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
590616
self.lock().write(buf)
591617
}
@@ -609,6 +635,7 @@ impl Write for Stdout {
609635
self.lock().write_fmt(args)
610636
}
611637
}
638+
612639
#[stable(feature = "rust1", since = "1.0.0")]
613640
impl Write for StdoutLock<'_> {
614641
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
@@ -762,6 +789,32 @@ impl fmt::Debug for Stderr {
762789

763790
#[stable(feature = "rust1", since = "1.0.0")]
764791
impl Write for Stderr {
792+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
793+
(&*self).write(buf)
794+
}
795+
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
796+
(&*self).write_vectored(bufs)
797+
}
798+
#[inline]
799+
fn is_write_vectored(&self) -> bool {
800+
io::Write::is_write_vectored(&&*self)
801+
}
802+
fn flush(&mut self) -> io::Result<()> {
803+
(&*self).flush()
804+
}
805+
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
806+
(&*self).write_all(buf)
807+
}
808+
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
809+
(&*self).write_all_vectored(bufs)
810+
}
811+
fn write_fmt(&mut self, args: fmt::Arguments<'_>) -> io::Result<()> {
812+
(&*self).write_fmt(args)
813+
}
814+
}
815+
816+
#[stable(feature = "write_mt", since = "1.48.0")]
817+
impl Write for &Stderr {
765818
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
766819
self.lock().write(buf)
767820
}
@@ -785,6 +838,7 @@ impl Write for Stderr {
785838
self.lock().write_fmt(args)
786839
}
787840
}
841+
788842
#[stable(feature = "rust1", since = "1.0.0")]
789843
impl Write for StderrLock<'_> {
790844
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {

library/std/src/io/util.rs

+24
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,30 @@ impl Write for Sink {
254254
}
255255
}
256256

257+
#[stable(feature = "write_mt", since = "1.48.0")]
258+
impl Write for &Sink {
259+
#[inline]
260+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
261+
Ok(buf.len())
262+
}
263+
264+
#[inline]
265+
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
266+
let total_len = bufs.iter().map(|b| b.len()).sum();
267+
Ok(total_len)
268+
}
269+
270+
#[inline]
271+
fn is_write_vectored(&self) -> bool {
272+
true
273+
}
274+
275+
#[inline]
276+
fn flush(&mut self) -> io::Result<()> {
277+
Ok(())
278+
}
279+
}
280+
257281
#[stable(feature = "std_debug", since = "1.16.0")]
258282
impl fmt::Debug for Sink {
259283
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

library/std/src/process.rs

+19
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,25 @@ pub struct ChildStdin {
249249

250250
#[stable(feature = "process", since = "1.0.0")]
251251
impl Write for ChildStdin {
252+
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
253+
(&*self).write(buf)
254+
}
255+
256+
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
257+
(&*self).write_vectored(bufs)
258+
}
259+
260+
fn is_write_vectored(&self) -> bool {
261+
io::Write::is_write_vectored(&&*self)
262+
}
263+
264+
fn flush(&mut self) -> io::Result<()> {
265+
(&*self).flush()
266+
}
267+
}
268+
269+
#[stable(feature = "write_mt", since = "1.48.0")]
270+
impl Write for &ChildStdin {
252271
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
253272
self.inner.write(buf)
254273
}

0 commit comments

Comments
 (0)