[−][src]Trait riker::actor::Receive
Receive and handle a specific message type
This trait is typically used in conjuction with the #[actor] attribute macro and implemented for each message type to receive.
Examples
#[derive(Clone, Debug)] pub struct Foo; #[derive(Clone, Debug)] pub struct Bar; #[actor(Foo, Bar)] // <-- set our actor to receive Foo and Bar types #[derive(Default)] struct MyActor; impl Actor for MyActor { type Msg = MyActorMsg; // <-- MyActorMsg is provided for us fn recv(&mut self, ctx: &Context<Self::Msg>, msg: Self::Msg, sender: Sender) { self.receive(ctx, msg, sender); // <-- call the respective implementation } } impl Receive<Foo> for MyActor { type Msg = MyActorMsg; fn receive(&mut self, ctx: &Context<Self::Msg>, msg: Foo, // <-- receive Foo sender: Sender) { println!("Received a Foo"); } } impl Receive<Bar> for MyActor { type Msg = MyActorMsg; fn receive(&mut self, ctx: &Context<Self::Msg>, msg: Bar, // <-- receive Bar sender: Sender) { println!("Received a Bar"); } } // main let sys = ActorSystem::new().unwrap(); let actor = sys.actor_of::<MyActor>("my-actor").unwrap(); actor.tell(Foo, None); actor.tell(Bar, None);
Associated Types
Loading content...Required methods
fn receive(
&mut self,
ctx: &Context<Self::Msg>,
msg: Msg,
sender: Option<BasicActorRef>
)
&mut self,
ctx: &Context<Self::Msg>,
msg: Msg,
sender: Option<BasicActorRef>
)
Invoked when an actor receives a message
It is guaranteed that only one message in the actor's mailbox is processed
at any one time, including receive
, other_receive
and system_receive
.
Implementors
impl Receive<ChannelMsg<SystemEvent>> for EventsChannel
[src]
type Msg = ChannelMsg<SystemEvent>
fn receive(
&mut self,
ctx: &Context<ChannelMsg<SystemEvent>>,
msg: Self::Msg,
sender: Sender
)
[src]
&mut self,
ctx: &Context<ChannelMsg<SystemEvent>>,
msg: Self::Msg,
sender: Sender
)
impl Receive<Publish<SystemEvent>> for EventsChannel
[src]
type Msg = ChannelMsg<SystemEvent>
fn receive(
&mut self,
ctx: &Context<ChannelMsg<SystemEvent>>,
msg: Publish<SystemEvent>,
sender: Sender
)
[src]
&mut self,
ctx: &Context<ChannelMsg<SystemEvent>>,
msg: Publish<SystemEvent>,
sender: Sender
)
impl<Msg> Receive<ChannelMsg<Msg>> for Channel<Msg> where
Msg: Message,
[src]
Msg: Message,
type Msg = ChannelMsg<Msg>
fn receive(
&mut self,
ctx: &Context<ChannelMsg<Msg>>,
msg: Self::Msg,
sender: Sender
)
[src]
&mut self,
ctx: &Context<ChannelMsg<Msg>>,
msg: Self::Msg,
sender: Sender
)
impl<Msg> Receive<Publish<Msg>> for Channel<Msg> where
Msg: Message,
[src]
Msg: Message,
type Msg = ChannelMsg<Msg>
fn receive(
&mut self,
ctx: &Context<ChannelMsg<Msg>>,
msg: Publish<Msg>,
sender: Sender
)
[src]
&mut self,
ctx: &Context<ChannelMsg<Msg>>,
msg: Publish<Msg>,
sender: Sender
)
impl<Msg> Receive<Subscribe<Msg>> for Channel<Msg> where
Msg: Message,
[src]
Msg: Message,
type Msg = ChannelMsg<Msg>
fn receive(
&mut self,
ctx: &Context<ChannelMsg<Msg>>,
msg: Subscribe<Msg>,
sender: Sender
)
[src]
&mut self,
ctx: &Context<ChannelMsg<Msg>>,
msg: Subscribe<Msg>,
sender: Sender
)
impl<Msg> Receive<Unsubscribe<Msg>> for Channel<Msg> where
Msg: Message,
[src]
Msg: Message,
type Msg = ChannelMsg<Msg>
fn receive(
&mut self,
ctx: &Context<ChannelMsg<Msg>>,
msg: Unsubscribe<Msg>,
sender: Sender
)
[src]
&mut self,
ctx: &Context<ChannelMsg<Msg>>,
msg: Unsubscribe<Msg>,
sender: Sender
)
impl<Msg> Receive<UnsubscribeAll<Msg>> for Channel<Msg> where
Msg: Message,
[src]
Msg: Message,
type Msg = ChannelMsg<Msg>
fn receive(
&mut self,
ctx: &Context<ChannelMsg<Msg>>,
msg: UnsubscribeAll<Msg>,
sender: Sender
)
[src]
&mut self,
ctx: &Context<ChannelMsg<Msg>>,
msg: UnsubscribeAll<Msg>,
sender: Sender
)