pub struct PartialAsyncRead<R> { /* private fields */ }
Available on crate feature futures03 only.
Expand description

A wrapper that breaks inner AsyncRead instances up according to the provided iterator.

Available with the futures03 feature for futures traits, and with the tokio1 feature for tokio traits.

Examples

This example uses tokio.

use partial_io::{PartialAsyncRead, PartialOp};
use std::io::{self, Cursor};
use tokio::io::AsyncReadExt;

#[tokio::main]
async fn main() -> io::Result<()> {
    let reader = Cursor::new(vec![1, 2, 3, 4]);
    // Sequential calls to `poll_read()` and the other `poll_` methods simulate the following behavior:
    let iter = vec![
        PartialOp::Err(io::ErrorKind::WouldBlock),   // A not-ready state.
        PartialOp::Limited(2),                       // Only allow 2 bytes to be read.
        PartialOp::Err(io::ErrorKind::InvalidData),  // Error from the underlying stream.
        PartialOp::Unlimited,                        // Allow as many bytes to be read as possible.
    ];
    let mut partial_reader = PartialAsyncRead::new(reader, iter);
    let mut out = vec![0; 256];

    // This causes poll_read to be called twice, yielding after the first call (WouldBlock).
    assert_eq!(partial_reader.read(&mut out).await?, 2, "first read with Limited(2)");
    assert_eq!(&out[..4], &[1, 2, 0, 0]);

    // This next call returns an error.
    assert_eq!(
        partial_reader.read(&mut out[2..]).await.unwrap_err().kind(),
        io::ErrorKind::InvalidData,
    );

    // And this one causes the last two bytes to be written.
    assert_eq!(partial_reader.read(&mut out[2..]).await?, 2, "second read with Unlimited");
    assert_eq!(&out[..4], &[1, 2, 3, 4]);

    Ok(())
}

Implementations

Creates a new PartialAsyncRead wrapper over the reader with the specified PartialOps.

Sets the PartialOps for this reader.

Sets the PartialOps for this reader in a pinned context.

Returns a shared reference to the underlying reader.

Returns a mutable reference to the underlying reader.

Returns a pinned mutable reference to the underlying reader.

Consumes this wrapper, returning the underlying reader.

Trait Implementations

Attempt to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to poll_read. Read more
Attempts to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Tells this buffer that amt bytes have been consumed from the buffer, so they should no longer be returned in calls to poll_read. Read more
Attempt to read from the AsyncRead into buf. Read more
Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more
Attempts to read from the AsyncRead into buf. Read more

This is a forwarding impl to support duplex structs.

Attempt to seek to an offset, in bytes, in a stream. Read more

This is a forwarding impl to support duplex structs.

Attempts to seek to an offset, in bytes, in a stream. Read more
Waits for a seek operation to complete. Read more

This is a forwarding impl to support duplex structs.

Attempt to write bytes from buf into the object. Read more
Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
Attempt to close the object. Read more
Attempt to write bytes from bufs into the object using vectored IO operations. Read more

This is a forwarding impl to support duplex structs.

Attempt to write bytes from buf into the object. Read more
Attempts to flush the object, ensuring that any buffered data reach their destination. Read more
Initiates or attempts to shut down this writer, returning success when the I/O connection has completely shut down. Read more
Like poll_write, except that it writes from a slice of buffers. Read more
Determines if this writer has an efficient poll_write_vectored implementation. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Creates a future which will wait for a non-empty buffer to be available from this I/O object or EOF to be reached. Read more
A convenience for calling [AsyncBufRead::consume] on Unpin IO types. Read more
Creates a future which will read all the bytes associated with this I/O object into buf until the delimiter byte or EOF is reached. This method is the async equivalent to BufRead::read_until. Read more
Creates a future which will read all the bytes associated with this I/O object into buf until a newline (the 0xA byte) or EOF is reached, This method is the async equivalent to BufRead::read_line. Read more
Returns a stream over the lines of this reader. This method is the async equivalent to BufRead::lines. Read more
Creates an adaptor which will chain this stream with another. Read more
Tries to read some bytes directly into the given buf in asynchronous manner, returning a future type. Read more
Creates a future which will read from the AsyncRead into bufs using vectored IO operations. Read more
Creates a future which will read exactly enough bytes to fill buf, returning an error if end of file (EOF) is hit sooner. Read more
Creates a future which will read all the bytes from this AsyncRead. Read more
Creates a future which will read all the bytes from this AsyncRead. Read more
Helper method for splitting this read/write object into two halves. Read more
Creates an AsyncRead adapter which will read at most limit bytes from the underlying reader. Read more
Creates a future which will seek an IO object, and then yield the new position in the object and the object itself. Read more
Creates a future which will return the current seek position from the start of the stream. Read more
Creates a future which will entirely flush this AsyncWrite. Read more
Creates a future which will entirely close this AsyncWrite.
Creates a future which will write bytes from buf into the object. Read more
Creates a future which will write bytes from bufs into the object using vectored IO operations. Read more
Write data into this object. Read more
Available on crate feature sink only.
Allow using an [AsyncWrite] as a Sink<Item: AsRef<[u8]>>. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.