pub trait MessageResponse<A: Actor, M: Message> {
// Required method
fn handle(self, ctx: &mut A::Context, tx: Option<OneshotSender<M::Result>>);
}
Expand description
A trait which defines message responses.
We offer implementation for some common language types, if you need
to respond with a new type you can use MessageResult
.
If Actor::Context
implements AsyncContext
it’s possible to handle
the message asynchronously.
For asynchronous message handling we offer the following possible response types:
ResponseFuture
should be used for when the future returned doesn’t need to access Actor’s internal state or context to progress, either because it’s completely agnostic to it or because the required data has already been moved to it and it won’t need Actor state to continue.ResponseActFuture
should be used when the future returned will, at some point, need to access Actor’s internal state or context in order to finish.AtomicResponse
should be used when the future returned needs exclusive access to Actor’s internal state or context.
Required Methods§
Implementations on Foreign Types§
Source§impl<A, M> MessageResponse<A, M> for bool
impl<A, M> MessageResponse<A, M> for bool
Source§impl<A, M> MessageResponse<A, M> for f32
impl<A, M> MessageResponse<A, M> for f32
Source§impl<A, M> MessageResponse<A, M> for f64
impl<A, M> MessageResponse<A, M> for f64
Source§impl<A, M> MessageResponse<A, M> for i8
impl<A, M> MessageResponse<A, M> for i8
Source§impl<A, M> MessageResponse<A, M> for i16
impl<A, M> MessageResponse<A, M> for i16
Source§impl<A, M> MessageResponse<A, M> for i32
impl<A, M> MessageResponse<A, M> for i32
Source§impl<A, M> MessageResponse<A, M> for i64
impl<A, M> MessageResponse<A, M> for i64
Source§impl<A, M> MessageResponse<A, M> for isize
impl<A, M> MessageResponse<A, M> for isize
Source§impl<A, M> MessageResponse<A, M> for u8
impl<A, M> MessageResponse<A, M> for u8
Source§impl<A, M> MessageResponse<A, M> for u16
impl<A, M> MessageResponse<A, M> for u16
Source§impl<A, M> MessageResponse<A, M> for u32
impl<A, M> MessageResponse<A, M> for u32
Source§impl<A, M> MessageResponse<A, M> for u64
impl<A, M> MessageResponse<A, M> for u64
Source§impl<A, M> MessageResponse<A, M> for ()
impl<A, M> MessageResponse<A, M> for ()
Source§impl<A, M> MessageResponse<A, M> for usize
impl<A, M> MessageResponse<A, M> for usize
Source§impl<A, M> MessageResponse<A, M> for String
impl<A, M> MessageResponse<A, M> for String
Source§impl<A, M, I> MessageResponse<A, M> for Option<I>
impl<A, M, I> MessageResponse<A, M> for Option<I>
Source§impl<A, M, I> MessageResponse<A, M> for Arc<I>
impl<A, M, I> MessageResponse<A, M> for Arc<I>
Source§impl<A, M, I> MessageResponse<A, M> for Vec<I>
impl<A, M, I> MessageResponse<A, M> for Vec<I>
Source§impl<A, M, I, E> MessageResponse<A, M> for Result<I, E>
impl<A, M, I, E> MessageResponse<A, M> for Result<I, E>
Implementors§
impl<A, M> MessageResponse<A, M> for ActorResponse<A, M::Result>
impl<A, M> MessageResponse<A, M> for AtomicResponse<A, M::Result>
impl<A, M> MessageResponse<A, M> for MessageResult<M>
impl<A, M> MessageResponse<A, M> for Response<M::Result>
impl<A, M> MessageResponse<A, M> for ResponseActFuture<A, M::Result>
impl<A, M> MessageResponse<A, M> for ResponseFuture<M::Result>
MessageResponse
trait impl to enable the use of any I: 'static
with asynchronous
message handling
§Examples
Usage with Result<I,E>
:
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 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 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})
}
}