[]Struct aiowrap::ShortRead

pub struct ShortRead<R, I> { /* fields omitted */ }

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());

Methods

impl<R, I: Iterator<Item = usize>> ShortRead<R, I>[src]

pub fn new(inner: R, decider: I) -> Self[src]

pub fn into_inner(self) -> R[src]

Trait Implementations

impl<R: AsyncRead, I: Iterator<Item = usize>> AsyncRead for ShortRead<R, I>[src]

impl<'__pin, R, I> Unpin for ShortRead<R, I> where
    __Origin<'__pin, R, I>: Unpin

Auto Trait Implementations

impl<R, I> RefUnwindSafe for ShortRead<R, I> where
    I: RefUnwindSafe,
    R: RefUnwindSafe

impl<R, I> Send for ShortRead<R, I> where
    I: Send,
    R: Send

impl<R, I> Sync for ShortRead<R, I> where
    I: Sync,
    R: Sync

impl<R, I> UnwindSafe for ShortRead<R, I> where
    I: UnwindSafe,
    R: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<R> AsyncReadExt for R where
    R: AsyncRead + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.