1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-10-21 17:33:59 +00:00

more general Responder implementaiton for response future

This commit is contained in:
Nikolay Kim 2017-12-20 15:26:28 -08:00
parent 821c96c37c
commit c36ad06332

View file

@ -168,14 +168,26 @@ impl<A: Actor<Context=HttpContext<A, S>>, S: 'static> From<HttpContext<A, S>> fo
}
}
impl Responder for Box<Future<Item=HttpResponse, Error=Error>>
impl<I, E> Responder for Box<Future<Item=I, Error=E>>
where I: Responder + 'static,
E: Into<Error> + 'static
{
type Item = Reply;
type Error = Error;
#[inline]
fn respond_to(self, _: HttpRequest) -> Result<Reply, Error> {
Ok(Reply(ReplyItem::Future(self)))
fn respond_to(self, req: HttpRequest) -> Result<Reply, Error> {
let fut = self.map_err(|e| e.into())
.then(move |r| {
match r.respond_to(req) {
Ok(reply) => match reply.into().0 {
ReplyItem::Message(resp) => ok(resp),
_ => panic!("Nested async replies are not supported"),
},
Err(e) => err(e),
}
});
Ok(Reply::async(fut))
}
}