[][src]Trait actix::dev::MessageResponse

pub trait MessageResponse<A: Actor, M: Message> {
    fn handle<R: ResponseChannel<M>>(self, ctx: &mut A::Context, tx: Option<R>);
}

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

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

Loading content...

Implementations on Foreign Types

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading content...

Implementors

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

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

impl<A, M, I: 'static> MessageResponse<A, M> for ResponseFuture<I> where
    A: Actor,
    M::Result: Send,
    M: Message<Result = I>,
    A::Context: AsyncContext<A>, 
[src]

MessageResponse trait impl to enbale 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})
    }
}

impl<A, M, I: 'static, E: 'static> MessageResponse<A, M> for ActorResponse<A, I, E> where
    A: Actor,
    M: Message<Result = Result<I, E>>,
    A::Context: AsyncContext<A>, 
[src]

impl<A, M, I: 'static, E: 'static> MessageResponse<A, M> for Response<I, E> where
    A: Actor,
    M: Message<Result = Result<I, E>>,
    A::Context: AsyncContext<A>, 
[src]

impl<A, M, T: 'static> MessageResponse<A, M> for AtomicResponse<A, T> where
    A: Actor,
    M: Message<Result = T>,
    A::Context: AsyncContext<A>, 
[src]

impl<A, M, T: 'static> MessageResponse<A, M> for ResponseActFuture<A, T> where
    A: Actor,
    M: Message<Result = T>,
    A::Context: AsyncContext<A>, 
[src]

Loading content...