pub trait AsyncWriteBody<W> {
    fn write_body<'life0, 'life1, 'async_trait>(
        self: Pin<&'life0 mut Self>,
        w: Pin<&'life1 mut W>
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
    where
        Self: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait
; fn reset<'life0, 'async_trait>(
        self: Pin<&'life0 mut Self>
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
    where
        W: 'async_trait,
        Self: 'async_trait,
        'life0: 'async_trait
; }
Expand description

A trait implemented by async streaming bodies.

This trait can most easily be implemented with the async-trait crate.

Examples

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

pub struct SimpleBodyWriter;

#[async_trait]
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
    where
        W: 'async_trait,
    {
        true
    }
}

Required Methods§

Writes the body out, in its entirety.

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

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.

Implementors§