From aeacf2ee1b8e74e296655f915bc5992d44d41fe6 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Mon, 1 Jun 2020 22:58:09 +0800 Subject: [PATCH] Remove Receive 'Msg' type, add actor trait bound --- examples/basic_panic.rs | 2 -- examples/channel.rs | 4 ---- examples/channel_dead_letters.rs | 4 ---- examples/channel_system.rs | 4 ---- examples/messaging.rs | 6 ------ examples/supervision_escalate.rs | 6 ------ examples/supervision_restart.rs | 4 ---- examples/supervision_stop.rs | 4 ---- riker-macros/src/lib.rs | 2 -- src/actor/actor.rs | 8 +------- src/actor/channel.rs | 14 -------------- src/system/system.rs | 2 -- tests/actors.rs | 4 ---- tests/channels.rs | 16 ---------------- tests/scheduling.rs | 8 -------- tests/supervision.rs | 16 ---------------- 16 files changed, 1 insertion(+), 103 deletions(-) diff --git a/examples/basic_panic.rs b/examples/basic_panic.rs index ea740c79..3424499f 100644 --- a/examples/basic_panic.rs +++ b/examples/basic_panic.rs @@ -38,8 +38,6 @@ impl Actor for PanicActor { } impl Receive for PanicActor { - type Msg = PanicActorMsg; - fn receive(&mut self, _ctx: &Context, _msg: Panic, _sender: Sender) { panic!("// TEST PANIC // TEST PANIC // TEST PANIC //"); } diff --git a/examples/channel.rs b/examples/channel.rs index 3c05fa32..b05757f6 100644 --- a/examples/channel.rs +++ b/examples/channel.rs @@ -41,8 +41,6 @@ impl Actor for GpsActor { } impl Receive for GpsActor { - type Msg = GpsActorMsg; - fn receive(&mut self, ctx: &Context, msg: PowerStatus, _sender: Sender) { println!("{}: -> got msg: {:?}", ctx.myself.name(), msg); } @@ -82,8 +80,6 @@ impl Actor for NavigationActor { } impl Receive for NavigationActor { - type Msg = NavigationActorMsg; - fn receive(&mut self, ctx: &Context, msg: PowerStatus, _sender: Sender) { println!("{}: -> got msg: {:?}", ctx.myself.name(), msg); } diff --git a/examples/channel_dead_letters.rs b/examples/channel_dead_letters.rs index fd0a650b..2a0ac052 100644 --- a/examples/channel_dead_letters.rs +++ b/examples/channel_dead_letters.rs @@ -19,8 +19,6 @@ impl Actor for DumbActor { } impl Receive for DumbActor { - type Msg = DumbActorMsg; - fn receive(&mut self, ctx: &Context, msg: SomeMessage, _sender: Sender) { println!("{}: -> got msg: {:?} ", ctx.myself.name(), msg); } @@ -55,8 +53,6 @@ impl Actor for DeadLetterActor { } impl Receive for DeadLetterActor { - type Msg = DeadLetterActorMsg; - fn receive(&mut self, ctx: &Context, msg: DeadLetter, _sender: Sender) { println!("{}: -> got msg: {:?} ", ctx.myself.name(), msg); } diff --git a/examples/channel_system.rs b/examples/channel_system.rs index ca9149c8..cebccb49 100644 --- a/examples/channel_system.rs +++ b/examples/channel_system.rs @@ -19,8 +19,6 @@ impl Actor for DumbActor { } impl Receive for DumbActor { - type Msg = DumbActorMsg; - fn receive(&mut self, _ctx: &Context, _msg: Panic, _sender: Sender) { panic!("// TEST PANIC // TEST PANIC // TEST PANIC //"); } @@ -65,8 +63,6 @@ impl Actor for SystemActor { } impl Receive for SystemActor { - type Msg = SystemActorMsg; - fn receive(&mut self, ctx: &Context, msg: SystemEvent, _sender: Sender) { print!("{}: -> got system msg: {:?} ", ctx.myself.name(), msg); match msg { diff --git a/examples/messaging.rs b/examples/messaging.rs index 6c79996e..9c005d70 100644 --- a/examples/messaging.rs +++ b/examples/messaging.rs @@ -37,24 +37,18 @@ impl Actor for Counter { } impl Receive for Counter { - type Msg = CounterMsg; - fn receive(&mut self, _ctx: &Context, _msg: Add, _sender: Sender) { self.count += 1; } } impl Receive for Counter { - type Msg = CounterMsg; - fn receive(&mut self, _ctx: &Context, _msg: Sub, _sender: Sender) { self.count -= 1; } } impl Receive for Counter { - type Msg = CounterMsg; - fn receive(&mut self, _ctx: &Context, _msg: Print, _sender: Sender) { println!("Total counter value: {}", self.count); } diff --git a/examples/supervision_escalate.rs b/examples/supervision_escalate.rs index 3e8c7cd3..ade21dee 100644 --- a/examples/supervision_escalate.rs +++ b/examples/supervision_escalate.rs @@ -38,8 +38,6 @@ impl Actor for PanicActor { } impl Receive for PanicActor { - type Msg = PanicActorMsg; - fn receive(&mut self, _ctx: &Context, _msg: Panic, _sender: Sender) { panic!("// TEST PANIC // TEST PANIC // TEST PANIC //"); } @@ -73,8 +71,6 @@ impl Actor for EscalateSup { } impl Receive for EscalateSup { - type Msg = EscalateSupMsg; - fn receive(&mut self, _ctx: &Context, _msg: Panic, _sender: Sender) { self.actor_to_fail.as_ref().unwrap().tell(Panic, None); } @@ -108,8 +104,6 @@ impl Actor for EscRestartSup { } impl Receive for EscRestartSup { - type Msg = EscRestartSupMsg; - fn receive(&mut self, _ctx: &Context, _msg: Panic, _sender: Sender) { self.escalator.as_ref().unwrap().tell(Panic, None); } diff --git a/examples/supervision_restart.rs b/examples/supervision_restart.rs index b57895a9..ac4d3c48 100644 --- a/examples/supervision_restart.rs +++ b/examples/supervision_restart.rs @@ -38,8 +38,6 @@ impl Actor for PanicActor { } impl Receive for PanicActor { - type Msg = PanicActorMsg; - fn receive(&mut self, _ctx: &Context, _msg: Panic, _sender: Sender) { panic!("// TEST PANIC // TEST PANIC // TEST PANIC //"); } @@ -69,8 +67,6 @@ impl Actor for RestartSup { } impl Receive for RestartSup { - type Msg = RestartSupMsg; - fn receive(&mut self, _ctx: &Context, _msg: Panic, _sender: Sender) { self.actor_to_fail.as_ref().unwrap().tell(Panic, None); } diff --git a/examples/supervision_stop.rs b/examples/supervision_stop.rs index 991095f6..c31d8659 100644 --- a/examples/supervision_stop.rs +++ b/examples/supervision_stop.rs @@ -38,8 +38,6 @@ impl Actor for PanicActor { } impl Receive for PanicActor { - type Msg = PanicActorMsg; - fn receive(&mut self, _ctx: &Context, _msg: Panic, _sender: Sender) { panic!("// TEST PANIC // TEST PANIC // TEST PANIC //"); } @@ -69,8 +67,6 @@ impl Actor for RestartSup { } impl Receive for RestartSup { - type Msg = RestartSupMsg; - fn receive(&mut self, _ctx: &Context, _msg: Panic, _sender: Sender) { self.actor_to_fail.as_ref().unwrap().tell(Panic, None); } diff --git a/riker-macros/src/lib.rs b/riker-macros/src/lib.rs index 63680bbf..a623adcd 100644 --- a/riker-macros/src/lib.rs +++ b/riker-macros/src/lib.rs @@ -108,8 +108,6 @@ fn receive(aname: &Ident, name: &Ident, types: &MsgTypes) -> TokenStream { }); quote! { impl Receive<#name> for #aname { - type Msg = #name; - fn receive(&mut self, ctx: &Context, msg: #name, diff --git a/src/actor/actor.rs b/src/actor/actor.rs index d3e805af..ea30872e 100644 --- a/src/actor/actor.rs +++ b/src/actor/actor.rs @@ -113,8 +113,6 @@ impl Actor for Box { /// } /// /// impl Receive for MyActor { -/// type Msg = MyActorMsg; -/// /// fn receive(&mut self, /// ctx: &Context, /// msg: Foo, // <-- receive Foo @@ -124,8 +122,6 @@ impl Actor for Box { /// } /// /// impl Receive for MyActor { -/// type Msg = MyActorMsg; -/// /// fn receive(&mut self, /// ctx: &Context, /// msg: Bar, // <-- receive Bar @@ -141,9 +137,7 @@ impl Actor for Box { /// actor.tell(Foo, None); /// actor.tell(Bar, None); /// ``` -pub trait Receive { - type Msg: Message; - +pub trait Receive: Actor { /// Invoked when an actor receives a message /// /// It is guaranteed that only one message in the actor's mailbox is processed diff --git a/src/actor/channel.rs b/src/actor/channel.rs index 3ea82798..af3c30e4 100644 --- a/src/actor/channel.rs +++ b/src/actor/channel.rs @@ -74,8 +74,6 @@ impl Receive> for Channel where Msg: Message, { - type Msg = ChannelMsg; - fn receive(&mut self, ctx: &ChannelCtx, msg: Self::Msg, sender: Sender) { match msg { ChannelMsg::Publish(p) => self.receive(ctx, p, sender), @@ -90,8 +88,6 @@ impl Receive> for Channel where Msg: Message, { - type Msg = ChannelMsg; - fn receive(&mut self, ctx: &ChannelCtx, msg: Subscribe, sender: Sender) { let subs = self.subs.entry(msg.topic).or_default(); subs.push(msg.actor); @@ -102,8 +98,6 @@ impl Receive> for Channel where Msg: Message, { - type Msg = ChannelMsg; - fn receive(&mut self, ctx: &ChannelCtx, msg: Unsubscribe, sender: Sender) { unsubscribe(&mut self.subs, &msg.topic, &msg.actor); } @@ -113,8 +107,6 @@ impl Receive> for Channel where Msg: Message, { - type Msg = ChannelMsg; - fn receive(&mut self, ctx: &ChannelCtx, msg: UnsubscribeAll, sender: Sender) { let subs = self.subs.clone(); @@ -128,8 +120,6 @@ impl Receive> for Channel where Msg: Message, { - type Msg = ChannelMsg; - fn receive(&mut self, ctx: &ChannelCtx, msg: Publish, sender: Sender) { // send system event to actors subscribed to all topics if let Some(subs) = self.subs.get(&All.into()) { @@ -187,8 +177,6 @@ impl Actor for EventsChannel { } impl Receive> for EventsChannel { - type Msg = ChannelMsg; - fn receive(&mut self, ctx: &ChannelCtx, msg: Self::Msg, sender: Sender) { // Publish variant uses specialized EventsChannel Receive // All other variants use the wrapped Channel (self.0) Receive(s) @@ -202,8 +190,6 @@ impl Receive> for EventsChannel { } impl Receive> for EventsChannel { - type Msg = ChannelMsg; - fn receive( &mut self, ctx: &ChannelCtx, diff --git a/src/system/system.rs b/src/system/system.rs index 19ba0cbb..2ce94e50 100644 --- a/src/system/system.rs +++ b/src/system/system.rs @@ -818,8 +818,6 @@ impl Actor for ShutdownActor { } impl Receive for ShutdownActor { - type Msg = SystemEvent; - fn receive( &mut self, ctx: &Context, diff --git a/tests/actors.rs b/tests/actors.rs index 2cf0f67c..6ca8faeb 100644 --- a/tests/actors.rs +++ b/tests/actors.rs @@ -29,16 +29,12 @@ impl Actor for Counter { } impl Receive for Counter { - type Msg = CounterMsg; - fn receive(&mut self, _ctx: &Context, msg: TestProbe, _sender: Sender) { self.probe = Some(msg) } } impl Receive for Counter { - type Msg = CounterMsg; - fn receive(&mut self, _ctx: &Context, _msg: Add, _sender: Sender) { self.count += 1; if self.count == 1_000_000 { diff --git a/tests/channels.rs b/tests/channels.rs index 89763a48..e9d11fe0 100644 --- a/tests/channels.rs +++ b/tests/channels.rs @@ -50,8 +50,6 @@ impl Actor for Subscriber { } impl Receive for Subscriber { - type Msg = SubscriberMsg; - fn receive(&mut self, _ctx: &Context, msg: TestProbe, _sender: Sender) { msg.0.event(()); self.probe = Some(msg); @@ -59,8 +57,6 @@ impl Receive for Subscriber { } impl Receive for Subscriber { - type Msg = SubscriberMsg; - fn receive(&mut self, _ctx: &Context, _msg: SomeMessage, _sender: Sender) { self.probe.as_ref().unwrap().0.event(()); } @@ -167,16 +163,12 @@ impl Actor for DumbActor { } impl Receive for DumbActor { - type Msg = DumbActorMsg; - fn receive(&mut self, _ctx: &Context, _msg: Panic, _sender: Sender) { panic!("// TEST PANIC // TEST PANIC // TEST PANIC //"); } } impl Receive for DumbActor { - type Msg = DumbActorMsg; - fn receive(&mut self, _ctx: &Context, _msg: SomeMessage, _sender: Sender) { // Intentionally left blank @@ -222,8 +214,6 @@ impl Actor for EventSubscriber { } impl Receive for EventSubscriber { - type Msg = EventSubscriberMsg; - fn receive(&mut self, _ctx: &Context, msg: TestProbe, _sender: Sender) { msg.0.event(()); self.probe = Some(msg); @@ -231,8 +221,6 @@ impl Receive for EventSubscriber { } impl Receive for EventSubscriber { - type Msg = EventSubscriberMsg; - fn receive(&mut self, _ctx: &Context, msg: SystemEvent, _sender: Sender) { match msg { SystemEvent::ActorCreated(created) => { @@ -311,8 +299,6 @@ impl Actor for DeadLetterSub { } impl Receive for DeadLetterSub { - type Msg = DeadLetterSubMsg; - fn receive(&mut self, _ctx: &Context, msg: TestProbe, _sender: Sender) { msg.0.event(()); self.probe = Some(msg); @@ -320,8 +306,6 @@ impl Receive for DeadLetterSub { } impl Receive for DeadLetterSub { - type Msg = DeadLetterSubMsg; - fn receive(&mut self, _ctx: &Context, _msg: DeadLetter, _sender: Sender) { self.probe.as_ref().unwrap().0.event(()); } diff --git a/tests/scheduling.rs b/tests/scheduling.rs index 0c96ab8b..475efce7 100644 --- a/tests/scheduling.rs +++ b/tests/scheduling.rs @@ -31,8 +31,6 @@ impl Actor for ScheduleOnce { } impl Receive for ScheduleOnce { - type Msg = ScheduleOnceMsg; - fn receive(&mut self, ctx: &Context, msg: TestProbe, _sender: Sender) { self.probe = Some(msg); // reschedule an Empty to be sent to myself() @@ -41,8 +39,6 @@ impl Receive for ScheduleOnce { } impl Receive for ScheduleOnce { - type Msg = ScheduleOnceMsg; - fn receive(&mut self, _ctx: &Context, _msg: SomeMessage, _sender: Sender) { self.probe.as_ref().unwrap().0.event(()); } @@ -93,8 +89,6 @@ impl Actor for ScheduleRepeat { } impl Receive for ScheduleRepeat { - type Msg = ScheduleRepeatMsg; - fn receive(&mut self, ctx: &Context, msg: TestProbe, _sender: Sender) { self.probe = Some(msg); // schedule Message to be repeatedly sent to myself @@ -111,8 +105,6 @@ impl Receive for ScheduleRepeat { } impl Receive for ScheduleRepeat { - type Msg = ScheduleRepeatMsg; - fn receive(&mut self, ctx: &Context, _msg: SomeMessage, _sender: Sender) { if self.counter == 5 { ctx.cancel_schedule(self.schedule_id.unwrap()); diff --git a/tests/supervision.rs b/tests/supervision.rs index e0d2564b..6c509d1c 100644 --- a/tests/supervision.rs +++ b/tests/supervision.rs @@ -44,16 +44,12 @@ impl Actor for PanicActor { } impl Receive for PanicActor { - type Msg = PanicActorMsg; - fn receive(&mut self, _ctx: &Context, msg: TestProbe, _sender: Sender) { msg.0.event(()); } } impl Receive for PanicActor { - type Msg = PanicActorMsg; - fn receive(&mut self, _ctx: &Context, _msg: Panic, _sender: Sender) { panic!("// TEST PANIC // TEST PANIC // TEST PANIC //"); } @@ -83,16 +79,12 @@ impl Actor for RestartSup { } impl Receive for RestartSup { - type Msg = RestartSupMsg; - fn receive(&mut self, _ctx: &Context, msg: TestProbe, sender: Sender) { self.actor_to_fail.as_ref().unwrap().tell(msg, sender); } } impl Receive for RestartSup { - type Msg = RestartSupMsg; - fn receive(&mut self, _ctx: &Context, _msg: Panic, _sender: Sender) { self.actor_to_fail.as_ref().unwrap().tell(Panic, None); } @@ -145,16 +137,12 @@ impl Actor for EscalateSup { } impl Receive for EscalateSup { - type Msg = EscalateSupMsg; - fn receive(&mut self, _ctx: &Context, msg: TestProbe, sender: Sender) { self.actor_to_fail.as_ref().unwrap().tell(msg, sender); } } impl Receive for EscalateSup { - type Msg = EscalateSupMsg; - fn receive(&mut self, _ctx: &Context, _msg: Panic, _sender: Sender) { self.actor_to_fail.as_ref().unwrap().tell(Panic, None); } @@ -188,16 +176,12 @@ impl Actor for EscRestartSup { } impl Receive for EscRestartSup { - type Msg = EscRestartSupMsg; - fn receive(&mut self, _ctx: &Context, msg: TestProbe, sender: Sender) { self.escalator.as_ref().unwrap().tell(msg, sender); } } impl Receive for EscRestartSup { - type Msg = EscRestartSupMsg; - fn receive(&mut self, _ctx: &Context, _msg: Panic, _sender: Sender) { self.escalator.as_ref().unwrap().tell(Panic, None); }