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

A trait implemented by asynchronous 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::server::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, mut w: Pin<&mut W>) -> Result<(), Error> {
        w.write_all(b"hello world").await.map_err(Error::internal_safe)
    }
}

Required Methods§

Writes the body out, in its entirety.

Implementors§