Repository: actix/actix (language: rust)

Issue:
Allow the use of any type inside a ResponseFuture
Allow the use of any type inside a ResponseFuture, like Option<> instead of Result<>.
See doc test for details.

Also see #312 


Discussion / hints:

Fix patch:
diff --git a/CHANGES.md b/CHANGES.md
index edc9898bc..72f4999bb 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -6,6 +6,12 @@
 
 * Fix `MessageResponse` implementation  for `ResponseFuture` to always poll the spawned `Future`. (#317)
 
+### Added
+
+* Allow return of any `T: 'static` on `ResponseFuture`. (#343)
+
+* Allow return of any `T: 'static` on `ResponseActFuture`. (#310)
+
 ## [0.9.0] 2019-12-20
 
 ### Fixed
diff --git a/src/handler.rs b/src/handler.rs
index 6e7994c4b..7fcd8b0c8 100644
--- a/src/handler.rs
+++ b/src/handler.rs
@@ -290,11 +290,67 @@ where
     }
 }
 
-impl<A, M, I: 'static, E: 'static> MessageResponse<A, M> for ResponseFuture<Result<I, E>>
+/// MessageResponse trait impl to enbale the use of any `I: 'static` with asynchronous
+/// message handling
+///
+/// # Examples
+/// Usage with `Result<I,E>`:
+/// ```
+/// # pub struct MyActorAsync {}
+/// # impl Actor for MyActorAsync { type Context = actix::Context<Self>; }
+/// # use actix::prelude::*;
+/// # use core::pin::Pin;
+/// #
+/// pub struct MyQuestion{}
+/// impl Message for MyQuestion {
+///     type Result = Result<u8,u8>;
+/// }
+/// impl Handler<MyQuestion> for MyActorAsync {
+///     type Result = ResponseFuture<Result<u8,u8>>;
+///     fn handle(&mut self, question: MyQuestion, _ctx: &mut Context<Self>) -> Self::Result {
+///         Box::pin(async {Ok(5)})
+///     }
+/// }
+/// ```
+/// Usage with `Option<I>`:
+/// ```
+/// # pub struct MyActorAsync {}
+/// # impl Actor for MyActorAsync { type Context = actix::Context<Self>; }
+/// # use actix::prelude::*;
+/// # use core::pin::Pin;
+/// pub struct MyQuestion{}
+/// impl Message for MyQuestion {
+///     type Result = Option<u8>;
+/// }
+/// impl Handler<MyQuestion> for MyActorAsync {
+///     type Result = ResponseFuture<Option<u8>>;
+///     fn handle(&mut self, question: MyQuestion, _ctx: &mut Context<Self>) -> Self::Result {
+///         Box::pin(async {Some(5)})
+///     }
+/// }
+/// ```
+/// Usage with any `I: 'static`:
+/// ```
+/// # pub struct MyActorAsync {}
+/// # impl Actor for MyActorAsync { type Context = actix::Context<Self>; }
+/// # use actix::prelude::*;
+/// # use core::pin::Pin;
+/// pub struct MyQuestion{}
+/// impl Message for MyQuestion {
+///     type Result = u8;
+/// }
+/// impl Handler<MyQuestion> for MyActorAsync {
+///     type Result = ResponseFuture<u8>;
+///     fn handle(&mut self, question: MyQuestion, _ctx: &mut Context<Self>) -> Self::Result {
+///         Box::pin(async {5})
+///     }
+/// }
+/// ```
+impl<A, M, I: 'static> MessageResponse<A, M> for ResponseFuture<I>
 where
     A: Actor,
     M::Result: Send,
-    M: Message<Result = Result<I, E>>,
+    M: Message<Result = I>,
     A::Context: AsyncContext<A>,
 {
     fn handle<R: ResponseChannel<M>>(self, _: &mut A::Context, tx: Option<R>) {


Test patch: