Skip to content

Commit 8250dbe

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

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

library/std/src/io/util.rs

+114
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,21 @@ 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+
186+
#[inline]
187+
fn write_fmt(&mut self, _fmt: fmt::Arguments<'_>) -> io::Result<()> {
188+
Ok(())
189+
}
190+
122191
#[inline]
123192
fn flush(&mut self) -> io::Result<()> {
124193
Ok(())
@@ -143,6 +212,21 @@ impl Write for &Empty {
143212
true
144213
}
145214

215+
#[inline]
216+
fn write_all(&mut self, _buf: &[u8]) -> io::Result<()> {
217+
Ok(())
218+
}
219+
220+
#[inline]
221+
fn write_all_vectored(&mut self, _bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
222+
Ok(())
223+
}
224+
225+
#[inline]
226+
fn write_fmt(&mut self, _fmt: fmt::Arguments<'_>) -> io::Result<()> {
227+
Ok(())
228+
}
229+
146230
#[inline]
147231
fn flush(&mut self) -> io::Result<()> {
148232
Ok(())
@@ -302,6 +386,21 @@ impl Write for Sink {
302386
true
303387
}
304388

389+
#[inline]
390+
fn write_all(&mut self, _buf: &[u8]) -> io::Result<()> {
391+
Ok(())
392+
}
393+
394+
#[inline]
395+
fn write_all_vectored(&mut self, _bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
396+
Ok(())
397+
}
398+
399+
#[inline]
400+
fn write_fmt(&mut self, _fmt: fmt::Arguments<'_>) -> io::Result<()> {
401+
Ok(())
402+
}
403+
305404
#[inline]
306405
fn flush(&mut self) -> io::Result<()> {
307406
Ok(())
@@ -326,6 +425,21 @@ impl Write for &Sink {
326425
true
327426
}
328427

428+
#[inline]
429+
fn write_all(&mut self, _buf: &[u8]) -> io::Result<()> {
430+
Ok(())
431+
}
432+
433+
#[inline]
434+
fn write_all_vectored(&mut self, _bufs: &mut [IoSlice<'_>]) -> io::Result<()> {
435+
Ok(())
436+
}
437+
438+
#[inline]
439+
fn write_fmt(&mut self, _fmt: fmt::Arguments<'_>) -> io::Result<()> {
440+
Ok(())
441+
}
442+
329443
#[inline]
330444
fn flush(&mut self) -> io::Result<()> {
331445
Ok(())

0 commit comments

Comments
 (0)