[][src]Trait futures_io::AsyncWrite

pub trait AsyncWrite {
    fn poll_write(
        self: Pin<&mut Self>,
        cx: &mut Context,
        buf: &[u8]
    ) -> Poll<Result<usize>>;
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>;
fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>; fn poll_vectored_write(
        self: Pin<&mut Self>,
        cx: &mut Context,
        vec: &[&IoVec]
    ) -> Poll<Result<usize>> { ... } }

Write bytes asynchronously.

This trait is analogous to the std::io::Write trait, but integrates with the asynchronous task system. In particular, the poll_write method, unlike Write::write, will automatically queue the current task for wakeup and return if data is not yet available, rather than blocking the calling thread.

Required methods

fn poll_write(
    self: Pin<&mut Self>,
    cx: &mut Context,
    buf: &[u8]
) -> Poll<Result<usize>>

Attempt to write bytes from buf into the object.

On success, returns Ok(Poll::Ready(num_bytes_written)).

If the object is not ready for writing, the method returns Ok(Poll::Pending) and arranges for the current task (via cx.waker().wake_by_ref()) to receive a notification when the object becomes readable or is closed.

Implementation

This function may not return errors of kind WouldBlock or Interrupted. Implementations must convert WouldBlock into Poll::Pending and either internally retry or convert Interrupted into another error kind.

fn poll_flush(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>

Attempt to flush the object, ensuring that any buffered data reach their destination.

On success, returns Ok(Poll::Ready(())).

If flushing cannot immediately complete, this method returns Ok(Poll::Pending) and arranges for the current task (via cx.waker().wake_by_ref()) to receive a notification when the object can make progress towards flushing.

Implementation

This function may not return errors of kind WouldBlock or Interrupted. Implementations must convert WouldBlock into Poll::Pending and either internally retry or convert Interrupted into another error kind.

fn poll_close(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Result<()>>

Attempt to close the object.

On success, returns Ok(Poll::Ready(())).

If closing cannot immediately complete, this function returns Ok(Poll::Pending) and arranges for the current task (via cx.waker().wake_by_ref()) to receive a notification when the object can make progress towards closing.

Implementation

This function may not return errors of kind WouldBlock or Interrupted. Implementations must convert WouldBlock into Poll::Pending and either internally retry or convert Interrupted into another error kind.

Loading content...

Provided methods

fn poll_vectored_write(
    self: Pin<&mut Self>,
    cx: &mut Context,
    vec: &[&IoVec]
) -> Poll<Result<usize>>

Attempt to write bytes from vec into the object using vectored IO operations.

This method is similar to poll_write, but allows data from multiple buffers to be written using a single operation.

On success, returns Ok(Poll::Ready(num_bytes_written)).

If the object is not ready for writing, the method returns Ok(Poll::Pending) and arranges for the current task (via cx.waker().wake_by_ref()) to receive a notification when the object becomes readable or is closed.

By default, this method delegates to using poll_write on the first buffer in vec. Objects which support vectored IO should override this method.

Implementation

This function may not return errors of kind WouldBlock or Interrupted. Implementations must convert WouldBlock into Poll::Pending and either internally retry or convert Interrupted into another error kind.

Loading content...

Implementations on Foreign Types

impl<T: ?Sized + AsyncWrite + Unpin> AsyncWrite for Box<T>[src]

impl<'a, T: ?Sized + AsyncWrite + Unpin> AsyncWrite for &'a mut T[src]

impl<'a, T: ?Sized + AsyncWrite> AsyncWrite for Pin<&'a mut T>[src]

impl<T: AsMut<[u8]> + Unpin> AsyncWrite for Cursor<T>[src]

fn poll_vectored_write(
    self: Pin<&mut Self>,
    cx: &mut Context,
    vec: &[&IoVec]
) -> Poll<Result<usize>>
[src]

impl AsyncWrite for Vec<u8>[src]

fn poll_vectored_write(
    self: Pin<&mut Self>,
    cx: &mut Context,
    vec: &[&IoVec]
) -> Poll<Result<usize>>
[src]

impl AsyncWrite for Sink[src]

fn poll_vectored_write(
    self: Pin<&mut Self>,
    cx: &mut Context,
    vec: &[&IoVec]
) -> Poll<Result<usize>>
[src]

Loading content...

Implementors

Loading content...