[−][src]Trait xtra::Handler
A trait indicating that an Actor
can handle a given Message
asynchronously, and the logic to handle the message. If the message should be handled synchronously,
then the SyncHandler
trait should rather be implemented.
Without the nightly
feature enabled, this is an async_trait
,
so implementations should be annotated #[async_trait]
.
Example
struct Msg; impl Message for Msg { type Result = u32; } #[async_trait::async_trait] impl Handler<Msg> for MyActor { async fn handle(&mut self, message: Msg, ctx: &mut Context<Self>) -> u32 { 20 } } #[smol_potat::main] async fn main() { let addr = MyActor.spawn(); assert_eq!(addr.send(Msg).await, Ok(20)); }
Required methods
fn handle<'s, 'c, 'handler>(
&'s mut self,
message: M,
ctx: &'c mut Context<Self>
) -> ResponderFut<'handler, M::Result> where
's: 'handler,
'c: 'handler,
&'s mut self,
message: M,
ctx: &'c mut Context<Self>
) -> ResponderFut<'handler, M::Result> where
's: 'handler,
'c: 'handler,
Handle a given message, returning its result.
Without the nightly
feature enabled, this is an async_trait
.
See the trait documentation to see an example of how this method can be declared.
Implementors
impl<M: Message, T: SyncHandler<M> + Send> Handler<M> for T
[src]
fn handle<'a, 'b, 'c>(
&'a mut self,
message: M,
ctx: &'b mut Context<Self>
) -> ResponderFut<'c, M::Result> where
'a: 'c,
'b: 'c,
[src]
&'a mut self,
message: M,
ctx: &'b mut Context<Self>
) -> ResponderFut<'c, M::Result> where
'a: 'c,
'b: 'c,