[][src]Struct partial_io::PartialAsyncWrite

pub struct PartialAsyncWrite<W> { /* fields omitted */ }

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

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

Examples

This example uses tokio.

use partial_io::{PartialAsyncWrite, PartialOp};
use std::io::Cursor;
use tokio::prelude::*;

#[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

impl<W> PartialAsyncWrite<W>[src]

pub fn new<I>(inner: W, iter: I) -> Self where
    I: IntoIterator<Item = PartialOp> + 'static,
    I::IntoIter: Send
[src]

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

pub fn set_ops<I>(&mut self, iter: I) -> &mut Self where
    I: IntoIterator<Item = PartialOp> + 'static,
    I::IntoIter: Send
[src]

Sets the PartialOps for this writer.

pub fn pin_set_ops<I>(self: Pin<&mut Self>, iter: I) -> Pin<&mut Self> where
    I: IntoIterator<Item = PartialOp> + 'static,
    I::IntoIter: Send
[src]

Sets the PartialOps for this writer in a pinned context.

pub fn get_ref(&self) -> &W[src]

Returns a shared reference to the underlying writer.

pub fn get_mut(&mut self) -> &mut W[src]

Returns a mutable reference to the underlying writer.

pub fn pin_get_mut(self: Pin<&mut Self>) -> Pin<&mut W>[src]

Returns a pinned mutable reference to the underlying writer.

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

Consumes this wrapper, returning the underlying writer.

Trait Implementations

impl<W> AsyncBufRead for PartialAsyncWrite<W> where
    W: AsyncBufRead
[src]

This is a forwarding impl to support duplex structs.

impl<W> AsyncBufRead for PartialAsyncWrite<W> where
    W: AsyncBufRead
[src]

This is a forwarding impl to support duplex structs.

impl<W> AsyncRead for PartialAsyncWrite<W> where
    W: AsyncRead
[src]

This is a forwarding impl to support duplex structs.

impl<W> AsyncRead for PartialAsyncWrite<W> where
    W: AsyncRead
[src]

This is a forwarding impl to support duplex structs.

impl<W> AsyncSeek for PartialAsyncWrite<W> where
    W: AsyncSeek
[src]

This is a forwarding impl to support duplex structs.

impl<W> AsyncSeek for PartialAsyncWrite<W> where
    W: AsyncSeek
[src]

This is a forwarding impl to support duplex structs.

impl<W> AsyncWrite for PartialAsyncWrite<W> where
    W: AsyncWrite
[src]

impl<W> AsyncWrite for PartialAsyncWrite<W> where
    W: AsyncWrite
[src]

impl<W> Debug for PartialAsyncWrite<W> where
    W: Debug
[src]

impl<W> PinnedDrop for PartialAsyncWrite<W>[src]

impl<'pin, W> Unpin for PartialAsyncWrite<W> where
    __PartialAsyncWrite<'pin, W>: Unpin
[src]

impl<W> UnsafeUnpin for PartialAsyncWrite<W>[src]

Auto Trait Implementations

impl<W> !RefUnwindSafe for PartialAsyncWrite<W>

impl<W> Send for PartialAsyncWrite<W> where
    W: Send

impl<W> !Sync for PartialAsyncWrite<W>

impl<W> !UnwindSafe for PartialAsyncWrite<W>

Blanket Implementations

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

impl<R> AsyncBufReadExt for R where
    R: AsyncBufRead + ?Sized
[src]

impl<R> AsyncBufReadExt for R where
    R: AsyncBufRead + ?Sized
[src]

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

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

impl<S> AsyncSeekExt for S where
    S: AsyncSeek + ?Sized
[src]

impl<S> AsyncSeekExt for S where
    S: AsyncSeek + ?Sized
[src]

impl<W> AsyncWriteExt for W where
    W: AsyncWrite + ?Sized
[src]

impl<W> AsyncWriteExt for W where
    W: AsyncWrite + ?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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,