LocalAsyncWriteBody

Trait LocalAsyncWriteBody 

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

A trait implemented by local async streaming bodies.

§Examples

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

pub struct SimpleBodyWriter;

impl<W> LocalAsyncWriteBody<W> for SimpleBodyWriter
where
    W: AsyncWrite,
{
    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>>

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>

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.

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§