[][src]Trait conjure_http::server::AsyncWriteBody

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

A trait implemented by asynchronous streaming bodies.

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

Examples

This example is not tested
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

Important traits for Pin<P>
fn write_body<'life0, 'async_trait>(
    self,
    w: Pin<&'life0 mut W>
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    Self: 'async_trait, 

Writes the body out, in its entirety.

Loading content...

Implementors

Loading content...