[][src]Trait actix_web::AsyncResponder

pub trait AsyncResponder<I, E>: Sized {
    fn responder(self) -> Box<dyn Future<Item = I, Error = E>>;
}

Convenience trait that converts Future object to a Boxed future

For example loading json from request's body is async operation.

use actix_web::{
    App, AsyncResponder, Error, HttpMessage, HttpRequest, HttpResponse,
};
use futures::future::Future;

#[derive(Deserialize, Debug)]
struct MyObj {
    name: String,
}

fn index(mut req: HttpRequest) -> Box<Future<Item = HttpResponse, Error = Error>> {
    req.json()                   // <- get JsonBody future
       .from_err()
       .and_then(|val: MyObj| {  // <- deserialized value
           Ok(HttpResponse::Ok().into())
       })
    // Construct boxed future by using `AsyncResponder::responder()` method
    .responder()
}

Required methods

fn responder(self) -> Box<dyn Future<Item = I, Error = E>>

Convert to a boxed future

Loading content...

Implementors

impl<F, I, E> AsyncResponder<I, E> for F where
    F: Future<Item = I, Error = E> + 'static,
    I: Responder + 'static,
    E: Into<Error> + 'static, 
[src]

Loading content...