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§

source

fn handle(self, ctx: &mut A::Context, tx: Option<OneshotSender<M::Result>>)

Implementations on Foreign Types§

source§

impl<A, M> MessageResponse<A, M> for bool
where A: Actor, M: Message<Result = bool>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<bool>>)

source§

impl<A, M> MessageResponse<A, M> for f32
where A: Actor, M: Message<Result = f32>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<f32>>)

source§

impl<A, M> MessageResponse<A, M> for f64
where A: Actor, M: Message<Result = f64>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<f64>>)

source§

impl<A, M> MessageResponse<A, M> for i8
where A: Actor, M: Message<Result = i8>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<i8>>)

source§

impl<A, M> MessageResponse<A, M> for i16
where A: Actor, M: Message<Result = i16>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<i16>>)

source§

impl<A, M> MessageResponse<A, M> for i32
where A: Actor, M: Message<Result = i32>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<i32>>)

source§

impl<A, M> MessageResponse<A, M> for i64
where A: Actor, M: Message<Result = i64>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<i64>>)

source§

impl<A, M> MessageResponse<A, M> for isize
where A: Actor, M: Message<Result = isize>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<isize>>)

source§

impl<A, M> MessageResponse<A, M> for u8
where A: Actor, M: Message<Result = u8>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<u8>>)

source§

impl<A, M> MessageResponse<A, M> for u16
where A: Actor, M: Message<Result = u16>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<u16>>)

source§

impl<A, M> MessageResponse<A, M> for u32
where A: Actor, M: Message<Result = u32>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<u32>>)

source§

impl<A, M> MessageResponse<A, M> for u64
where A: Actor, M: Message<Result = u64>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<u64>>)

source§

impl<A, M> MessageResponse<A, M> for ()
where A: Actor, M: Message<Result = ()>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<()>>)

source§

impl<A, M> MessageResponse<A, M> for usize
where A: Actor, M: Message<Result = usize>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<usize>>)

source§

impl<A, M> MessageResponse<A, M> for String
where A: Actor, M: Message<Result = String>,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<String>>)

source§

impl<A, M, I> MessageResponse<A, M> for Option<I>
where A: Actor, M: Message<Result = Self>, I: 'static,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<Self>>)

source§

impl<A, M, I> MessageResponse<A, M> for Arc<I>
where A: Actor, M: Message<Result = Self>, I: 'static,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<Self>>)

source§

impl<A, M, I> MessageResponse<A, M> for Vec<I>
where A: Actor, M: Message<Result = Self>, I: 'static,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<Self>>)

source§

impl<A, M, I, E> MessageResponse<A, M> for Result<I, E>
where A: Actor, M: Message<Result = Self>, I: 'static, E: 'static,

source§

fn handle(self, _: &mut A::Context, tx: Option<OneshotSender<Self>>)

Implementors§

source§

impl<A, M> MessageResponse<A, M> for ActorResponse<A, M::Result>
where A: Actor, M: Message, A::Context: AsyncContext<A>,

source§

impl<A, M> MessageResponse<A, M> for AtomicResponse<A, M::Result>
where A: Actor, M: Message, A::Context: AsyncContext<A>,

source§

impl<A, M> MessageResponse<A, M> for MessageResult<M>
where A: Actor, M: Message,

source§

impl<A, M> MessageResponse<A, M> for Response<M::Result>
where A: Actor, M: Message,

source§

impl<A, M> MessageResponse<A, M> for ResponseActFuture<A, M::Result>
where A: Actor, M: Message, A::Context: AsyncContext<A>,

source§

impl<A, M> MessageResponse<A, M> for ResponseFuture<M::Result>
where A: Actor, M: Message,

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})
    }
}
source§

impl<A, M, B> MessageResponse<A, M> for Addr<B>
where A: Actor, M: Message<Result = Self>, B: Actor,