Repository: actix/actix (language: rust)

Issue:
Implement MessageResponse for Option<T>
This is fairly self-explanatory. It would be nice to have Option<T> implement MessageResponse, so that Option<T> could be the result of a Handler.


Discussion / hints:

Fix patch:
diff --git a/src/handler.rs b/src/handler.rs
index 091c55075..27b2ea6a0 100644
--- a/src/handler.rs
+++ b/src/handler.rs
@@ -98,6 +98,18 @@ where
     }
 }
 
+impl<A, M, I: 'static> MessageResponse<A, M> for Option<I>
+where
+    A: Actor,
+    M: Message<Result = Option<I>>,
+{
+    fn handle<R: ResponseChannel<M>>(self, _: &mut A::Context, tx: Option<R>) {
+        if let Some(tx) = tx {
+            tx.send(self);
+        }
+    }
+}
+
 impl<A, M, B> MessageResponse<A, M> for Addr<B>
 where
     A: Actor,


Test patch: