read_buf
This commit is contained in:
@@ -5,7 +5,7 @@ mod tests;
|
||||
|
||||
use crate::fmt;
|
||||
use crate::io::{
|
||||
self, BufRead, Initializer, IoSlice, IoSliceMut, Read, Seek, SeekFrom, SizeHint, Write,
|
||||
self, BufRead, IoSlice, IoSliceMut, Read, ReadBuf, Seek, SeekFrom, SizeHint, Write,
|
||||
};
|
||||
|
||||
/// A reader which is always at EOF.
|
||||
@@ -47,8 +47,8 @@ impl Read for Empty {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn initializer(&self) -> Initializer {
|
||||
Initializer::nop()
|
||||
fn read_buf(&mut self, _buf: &mut ReadBuf<'_>) -> io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
@@ -130,6 +130,22 @@ impl Read for Repeat {
|
||||
Ok(buf.len())
|
||||
}
|
||||
|
||||
fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> io::Result<()> {
|
||||
for slot in unsafe { buf.unfilled_mut() } {
|
||||
slot.write(self.byte);
|
||||
}
|
||||
|
||||
let remaining = buf.remaining();
|
||||
|
||||
unsafe {
|
||||
buf.assume_init(remaining);
|
||||
}
|
||||
|
||||
buf.add_filled(remaining);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
|
||||
let mut nwritten = 0;
|
||||
@@ -143,11 +159,6 @@ impl Read for Repeat {
|
||||
fn is_read_vectored(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn initializer(&self) -> Initializer {
|
||||
Initializer::nop()
|
||||
}
|
||||
}
|
||||
|
||||
impl SizeHint for Repeat {
|
||||
|
||||
Reference in New Issue
Block a user