Skip to content

Commit 854723e

Browse files
committed
Implement default methods for io::Empty and io::Sink
1 parent d8810e3 commit 854723e

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

library/std/src/io/util.rs

+99
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,81 @@ impl Read for Empty {
6868
fn read_buf(&mut self, _cursor: BorrowedCursor<'_>) -> io::Result<()> {
6969
Ok(())
7070
}
71+
72+
#[inline]
73+
fn read_vectored(&mut self, _bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
74+
Ok(0)
75+
}
76+
77+
#[inline]
78+
fn is_read_vectored(&self) -> bool {
79+
true
80+
}
81+
82+
#[inline]
83+
fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> {
84+
if !buf.is_empty() { Err(io::Error::READ_EXACT_EOF) } else { Ok(()) }
85+
}
86+
87+
#[inline]
88+
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
89+
if cursor.capacity() != 0 { Err(io::Error::READ_EXACT_EOF) } else { Ok(()) }
90+
}
91+
92+
#[inline]
93+
fn read_to_end(&mut self, _buf: &mut Vec<u8>) -> io::Result<usize> {
94+
Ok(0)
95+
}
96+
97+
#[inline]
98+
fn read_to_string(&mut self, _buf: &mut String) -> io::Result<usize> {
99+
Ok(0)
100+
}
71101
}
72102
#[stable(feature = "rust1", since = "1.0.0")]
73103
impl BufRead for Empty {
74104
#[inline]
75105
fn fill_buf(&mut self) -> io::Result<&[u8]> {
76106
Ok(&[])
77107
}
108+
78109
#[inline]
79110
fn consume(&mut self, _n: usize) {}
111+
112+
#[inline]
113+
fn has_data_left(&mut self) -> io::Result<bool> {
114+
Ok(false)
115+
}
116+
117+
#[inline]
118+
fn read_until(&mut self, _byte: u8, _buf: &mut Vec<u8>) -> io::Result<usize> {
119+
Ok(0)
120+
}
121+
122+
#[inline]
123+
fn skip_until(&mut self, _byte: u8) -> io::Result<usize> {
124+
Ok(0)
125+
}
126+
127+
#[inline]
128+
fn read_line(&mut self, _buf: &mut String) -> io::Result<usize> {
129+
Ok(0)
130+
}
80131
}
81132

82133
#[stable(feature = "empty_seek", since = "1.51.0")]
83134
impl Seek for Empty {
135+
#[inline]
84136
fn seek(&mut self, _pos: SeekFrom) -> io::Result<u64> {
85137
Ok(0)
86138
}
87139

140+
#[inline]
88141
fn stream_len(&mut self) -> io::Result<u64> {
89142
Ok(0)
90143
}
91144

145+
#[inline]
92146
fn stream_position(&mut self) -> io::Result<u64> {
93147
Ok(0)
94148
}
@@ -119,6 +173,16 @@ impl Write for Empty {
119173
true
120174
}
121175

176+
#[inline]
177+
fn write_all(&mut self, _buf: &[u8]) -> io::Result<()> {
178+
Ok(())
179+
}
180+
181+
#[inline]
182+
fn write_all_vectored(&mut self, _bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
183+
Ok(())
184+
}
185+
122186
#[inline]
123187
fn flush(&mut self) -> io::Result<()> {
124188
Ok(())
@@ -143,6 +207,16 @@ impl Write for &Empty {
143207
true
144208
}
145209

210+
#[inline]
211+
fn write_all(&mut self, _buf: &[u8]) -> io::Result<()> {
212+
Ok(())
213+
}
214+
215+
#[inline]
216+
fn write_all_vectored(&mut self, _bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
217+
Ok(())
218+
}
219+
146220
#[inline]
147221
fn flush(&mut self) -> io::Result<()> {
148222
Ok(())
@@ -302,6 +376,16 @@ impl Write for Sink {
302376
true
303377
}
304378

379+
#[inline]
380+
fn write_all(&mut self, _buf: &[u8]) -> io::Result<()> {
381+
Ok(())
382+
}
383+
384+
#[inline]
385+
fn write_all_vectored(&mut self, _bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
386+
Ok(())
387+
}
388+
305389
#[inline]
306390
fn flush(&mut self) -> io::Result<()> {
307391
Ok(())
@@ -326,6 +410,21 @@ impl Write for &Sink {
326410
true
327411
}
328412

413+
#[inline]
414+
fn write_all(&mut self, _buf: &[u8]) -> io::Result<()> {
415+
Ok(())
416+
}
417+
418+
#[inline]
419+
fn write_all_vectored(&mut self, _bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
420+
Ok(())
421+
}
422+
423+
#[inline]
424+
fn write_fmt(&mut self, _fmt: fmt::Arguments<'_>) -> io::Result<()> {
425+
Ok(())
426+
}
427+
329428
#[inline]
330429
fn flush(&mut self) -> io::Result<()> {
331430
Ok(())

0 commit comments

Comments
 (0)