Trait conjure_http::client::AsyncWriteBody

source ·
pub trait AsyncWriteBody<W> {
    // Required methods
    fn write_body(
        self: Pin<&mut Self>,
        w: Pin<&mut W>,
    ) -> impl Future<Output = Result<(), Error>> + Send;
    fn reset(self: Pin<&mut Self>) -> impl Future<Output = bool> + Send;
}
Expand description

A trait implemented by async streaming bodies.

§Examples

use conjure_error::Error;
use conjure_http::client::AsyncWriteBody;
use std::pin::Pin;
use tokio_io::{AsyncWrite, AsyncWriteExt};

pub struct SimpleBodyWriter;

impl<W> AsyncWriteBody<W> for SimpleBodyWriter
where
    W: AsyncWrite + Send,
{
    async fn write_body(self: Pin<&mut Self>, mut w: Pin<&mut W>) -> Result<(), Error> {
        w.write_all(b"hello world").await.map_err(Error::internal_safe)
    }

    async fn reset(self: Pin<&mut Self>) -> bool {
        true
    }
}

Required Methods§

source

fn write_body( self: Pin<&mut Self>, w: Pin<&mut W>, ) -> impl Future<Output = Result<(), Error>> + Send

Writes the body out, in its entirety.

Behavior is unspecified if this method is called twice without a successful call to reset in between.

source

fn reset(self: Pin<&mut Self>) -> impl Future<Output = bool> + Send

Attempts to reset the body so that it can be written out again.

Returns true if successful. Behavior is unspecified if this is not called after a call to write_body.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<W> AsyncWriteBody<W> for BoxAsyncWriteBody<'_, W>
where W: Send,