pub struct PartialAsyncWrite<W> { /* private fields */ }
Expand description

A wrapper that breaks inner AsyncWrite 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::{PartialAsyncWrite, PartialOp};
use std::io::{self, Cursor};
use tokio::io::AsyncWriteExt;

#[tokio::main]
async fn main() -> io::Result<()> {
    let writer = Cursor::new(Vec::new());
    // Sequential calls to `poll_write()` 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 written.
        PartialOp::Err(io::ErrorKind::InvalidData),  // Error from the underlying stream.
        PartialOp::Unlimited,                        // Allow as many bytes to be written as possible.
    ];
    let mut partial_writer = PartialAsyncWrite::new(writer, iter);
    let in_data = vec![1, 2, 3, 4];

    // This causes poll_write to be called twice, yielding after the first call (WouldBlock).
    assert_eq!(partial_writer.write(&in_data).await?, 2);
    let cursor_ref = partial_writer.get_ref();
    let out = cursor_ref.get_ref();
    assert_eq!(&out[..], &[1, 2]);

    // This next call returns an error.
    assert_eq!(
        partial_writer.write(&in_data[2..]).await.unwrap_err().kind(),
        io::ErrorKind::InvalidData,
    );

    // And this one causes the last two bytes to be written.
    assert_eq!(partial_writer.write(&in_data[2..]).await?, 2);
    let cursor_ref = partial_writer.get_ref();
    let out = cursor_ref.get_ref();
    assert_eq!(&out[..], &[1, 2, 3, 4]);

    Ok(())
}

Implementations

Available on crate feature futures03 only.

Creates a new PartialAsyncWrite wrapper over the writer with the specified PartialOps.

Available on crate feature futures03 only.

Sets the PartialOps for this writer.

Available on crate feature futures03 only.

Sets the PartialOps for this writer in a pinned context.

Available on crate feature futures03 only.

Returns a shared reference to the underlying writer.

Available on crate feature futures03 only.

Returns a mutable reference to the underlying writer.

Available on crate feature futures03 only.

Returns a pinned mutable reference to the underlying writer.

Available on crate feature futures03 only.

Consumes this wrapper, returning the underlying writer.

Trait Implementations

This is a forwarding impl to support duplex structs.

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

This is a forwarding impl to support duplex structs.

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

This is a forwarding impl to support duplex structs.

Attempt to read from the AsyncRead into buf. Read more

Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more

This is a forwarding impl to support duplex structs.

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

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

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.