AsyncWriteBody

Trait AsyncWriteBody 

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

A trait implemented by asynchronous streaming bodies.

§Examples

use conjure_error::Error;
use conjure_http::server::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, mut w: Pin<&mut W>) -> Result<(), Error> {
        w.write_all(b"hello world").await.map_err(Error::internal_safe)
    }
}

Required Methods§

Source

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

Writes the body out, in its entirety.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

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