pub struct ShortRead<R, I> { /* private fields */ }
Expand description
Intentionally return short reads, to test AsyncRead
code.
The decider
iterator gets to decide how short a read should be.
A read length of 0 generates an Poll::Pending
, with an immediate wakeup.
When the iterator runs out before the reader, read
will always
return zero-length reads (EOF).
Currently, no effort is made to make reads longer, if the underlying reader naturally returns short reads.
§Examples
Short read:
use futures::io;
use futures::io::AsyncReadExt as _;
let mut naughty = aiowrap::ShortRead::new(
io::Cursor::new(b"1234567890"),
vec![2, 3, 4, 5, 6].into_iter()
);
let mut buf = [0u8; 10];
// A `Cursor` would normally return the whole ten bytes here,
// but we've limited it to two bytes.
assert_eq!(2, naughty.read(&mut buf).await.unwrap());
Implementations§
Trait Implementations§
Source§impl<R: AsyncRead, I: Iterator<Item = usize>> AsyncRead for ShortRead<R, I>
impl<R: AsyncRead, I: Iterator<Item = usize>> AsyncRead for ShortRead<R, I>
impl<'__pin, R, I> Unpin for ShortRead<R, I>where
__Origin<'__pin, R, I>: Unpin,
Auto Trait Implementations§
impl<R, I> Freeze for ShortRead<R, I>
impl<R, I> RefUnwindSafe for ShortRead<R, I>where
R: RefUnwindSafe,
I: RefUnwindSafe,
impl<R, I> Send for ShortRead<R, I>
impl<R, I> Sync for ShortRead<R, I>
impl<R, I> UnwindSafe for ShortRead<R, I>where
R: UnwindSafe,
I: UnwindSafe,
Blanket Implementations§
Source§impl<R> AsyncReadExt for R
impl<R> AsyncReadExt for R
Source§fn chain<R>(self, next: R) -> Chain<Self, R>
fn chain<R>(self, next: R) -> Chain<Self, R>
Creates an adaptor which will chain this stream with another. Read more
Source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
Tries to read some bytes directly into the given
buf
in asynchronous
manner, returning a future type. Read moreSource§fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectored<'a, Self>where
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectored<'a, Self>where
Self: Unpin,
Creates a future which will read from the
AsyncRead
into bufs
using vectored
IO operations. Read moreSource§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
Creates a future which will read exactly enough bytes to fill
buf
,
returning an error if end of file (EOF) is hit sooner. Read moreSource§fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
Creates a future which will read all the bytes from this
AsyncRead
. Read moreSource§fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToString<'a, Self>where
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToString<'a, Self>where
Self: Unpin,
Creates a future which will read all the bytes from this
AsyncRead
. Read moreSource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more