Skip to content

Commit

Permalink
Remove Receive 'Msg' type, add actor trait bound
Browse files Browse the repository at this point in the history
  • Loading branch information
mkj committed Jun 1, 2020
1 parent d43f5d3 commit 113178b
Show file tree
Hide file tree
Showing 16 changed files with 1 addition and 102 deletions.
2 changes: 0 additions & 2 deletions examples/basic_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ impl Actor for PanicActor {
}

impl Receive<Panic> for PanicActor {
type Msg = PanicActorMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: Panic, _sender: Sender) {
panic!("// TEST PANIC // TEST PANIC // TEST PANIC //");
}
Expand Down
4 changes: 0 additions & 4 deletions examples/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ impl Actor for GpsActor {
}

impl Receive<PowerStatus> for GpsActor {
type Msg = GpsActorMsg;

fn receive(&mut self, ctx: &Context<Self::Msg>, msg: PowerStatus, _sender: Sender) {
println!("{}: -> got msg: {:?}", ctx.myself.name(), msg);
}
Expand Down Expand Up @@ -82,8 +80,6 @@ impl Actor for NavigationActor {
}

impl Receive<PowerStatus> for NavigationActor {
type Msg = NavigationActorMsg;

fn receive(&mut self, ctx: &Context<Self::Msg>, msg: PowerStatus, _sender: Sender) {
println!("{}: -> got msg: {:?}", ctx.myself.name(), msg);
}
Expand Down
4 changes: 0 additions & 4 deletions examples/channel_dead_letters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ impl Actor for DumbActor {
}

impl Receive<SomeMessage> for DumbActor {
type Msg = DumbActorMsg;

fn receive(&mut self, ctx: &Context<Self::Msg>, msg: SomeMessage, _sender: Sender) {
println!("{}: -> got msg: {:?} ", ctx.myself.name(), msg);
}
Expand Down Expand Up @@ -55,8 +53,6 @@ impl Actor for DeadLetterActor {
}

impl Receive<DeadLetter> for DeadLetterActor {
type Msg = DeadLetterActorMsg;

fn receive(&mut self, ctx: &Context<Self::Msg>, msg: DeadLetter, _sender: Sender) {
println!("{}: -> got msg: {:?} ", ctx.myself.name(), msg);
}
Expand Down
4 changes: 0 additions & 4 deletions examples/channel_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ impl Actor for DumbActor {
}

impl Receive<Panic> for DumbActor {
type Msg = DumbActorMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: Panic, _sender: Sender) {
panic!("// TEST PANIC // TEST PANIC // TEST PANIC //");
}
Expand Down Expand Up @@ -65,8 +63,6 @@ impl Actor for SystemActor {
}

impl Receive<SystemEvent> for SystemActor {
type Msg = SystemActorMsg;

fn receive(&mut self, ctx: &Context<Self::Msg>, msg: SystemEvent, _sender: Sender) {
print!("{}: -> got system msg: {:?} ", ctx.myself.name(), msg);
match msg {
Expand Down
6 changes: 0 additions & 6 deletions examples/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,18 @@ impl Actor for Counter {
}

impl Receive<Add> for Counter {
type Msg = CounterMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: Add, _sender: Sender) {
self.count += 1;
}
}

impl Receive<Sub> for Counter {
type Msg = CounterMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: Sub, _sender: Sender) {
self.count -= 1;
}
}

impl Receive<Print> for Counter {
type Msg = CounterMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: Print, _sender: Sender) {
println!("Total counter value: {}", self.count);
}
Expand Down
6 changes: 0 additions & 6 deletions examples/supervision_escalate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ impl Actor for PanicActor {
}

impl Receive<Panic> for PanicActor {
type Msg = PanicActorMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: Panic, _sender: Sender) {
panic!("// TEST PANIC // TEST PANIC // TEST PANIC //");
}
Expand Down Expand Up @@ -73,8 +71,6 @@ impl Actor for EscalateSup {
}

impl Receive<Panic> for EscalateSup {
type Msg = EscalateSupMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: Panic, _sender: Sender) {
self.actor_to_fail.as_ref().unwrap().tell(Panic, None);
}
Expand Down Expand Up @@ -108,8 +104,6 @@ impl Actor for EscRestartSup {
}

impl Receive<Panic> for EscRestartSup {
type Msg = EscRestartSupMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: Panic, _sender: Sender) {
self.escalator.as_ref().unwrap().tell(Panic, None);
}
Expand Down
4 changes: 0 additions & 4 deletions examples/supervision_restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ impl Actor for PanicActor {
}

impl Receive<Panic> for PanicActor {
type Msg = PanicActorMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: Panic, _sender: Sender) {
panic!("// TEST PANIC // TEST PANIC // TEST PANIC //");
}
Expand Down Expand Up @@ -69,8 +67,6 @@ impl Actor for RestartSup {
}

impl Receive<Panic> for RestartSup {
type Msg = RestartSupMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: Panic, _sender: Sender) {
self.actor_to_fail.as_ref().unwrap().tell(Panic, None);
}
Expand Down
4 changes: 0 additions & 4 deletions examples/supervision_stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ impl Actor for PanicActor {
}

impl Receive<Panic> for PanicActor {
type Msg = PanicActorMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: Panic, _sender: Sender) {
panic!("// TEST PANIC // TEST PANIC // TEST PANIC //");
}
Expand Down Expand Up @@ -69,8 +67,6 @@ impl Actor for RestartSup {
}

impl Receive<Panic> for RestartSup {
type Msg = RestartSupMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: Panic, _sender: Sender) {
self.actor_to_fail.as_ref().unwrap().tell(Panic, None);
}
Expand Down
2 changes: 0 additions & 2 deletions riker-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Msg>,
msg: #name,
Expand Down
7 changes: 1 addition & 6 deletions src/actor/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ impl<A: Actor + ?Sized> Actor for Box<A> {
/// }
///
/// impl Receive<Foo> for MyActor {
/// type Msg = MyActorMsg;
///
/// fn receive(&mut self,
/// ctx: &Context<Self::Msg>,
/// msg: Foo, // <-- receive Foo
Expand All @@ -124,8 +122,6 @@ impl<A: Actor + ?Sized> Actor for Box<A> {
/// }
///
/// impl Receive<Bar> for MyActor {
/// type Msg = MyActorMsg;
///
/// fn receive(&mut self,
/// ctx: &Context<Self::Msg>,
/// msg: Bar, // <-- receive Bar
Expand All @@ -141,8 +137,7 @@ impl<A: Actor + ?Sized> Actor for Box<A> {
/// actor.tell(Foo, None);
/// actor.tell(Bar, None);
/// ```
pub trait Receive<Msg: Message> {
type Msg: Message;
pub trait Receive<Msg: Message> : Actor {

/// Invoked when an actor receives a message
///
Expand Down
14 changes: 0 additions & 14 deletions src/actor/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ impl<Msg> Receive<ChannelMsg<Msg>> for Channel<Msg>
where
Msg: Message,
{
type Msg = ChannelMsg<Msg>;

fn receive(&mut self, ctx: &ChannelCtx<Msg>, msg: Self::Msg, sender: Sender) {
match msg {
ChannelMsg::Publish(p) => self.receive(ctx, p, sender),
Expand All @@ -90,8 +88,6 @@ impl<Msg> Receive<Subscribe<Msg>> for Channel<Msg>
where
Msg: Message,
{
type Msg = ChannelMsg<Msg>;

fn receive(&mut self, ctx: &ChannelCtx<Msg>, msg: Subscribe<Msg>, sender: Sender) {
let subs = self.subs.entry(msg.topic).or_default();
subs.push(msg.actor);
Expand All @@ -102,8 +98,6 @@ impl<Msg> Receive<Unsubscribe<Msg>> for Channel<Msg>
where
Msg: Message,
{
type Msg = ChannelMsg<Msg>;

fn receive(&mut self, ctx: &ChannelCtx<Msg>, msg: Unsubscribe<Msg>, sender: Sender) {
unsubscribe(&mut self.subs, &msg.topic, &msg.actor);
}
Expand All @@ -113,8 +107,6 @@ impl<Msg> Receive<UnsubscribeAll<Msg>> for Channel<Msg>
where
Msg: Message,
{
type Msg = ChannelMsg<Msg>;

fn receive(&mut self, ctx: &ChannelCtx<Msg>, msg: UnsubscribeAll<Msg>, sender: Sender) {
let subs = self.subs.clone();

Expand All @@ -128,8 +120,6 @@ impl<Msg> Receive<Publish<Msg>> for Channel<Msg>
where
Msg: Message,
{
type Msg = ChannelMsg<Msg>;

fn receive(&mut self, ctx: &ChannelCtx<Msg>, msg: Publish<Msg>, sender: Sender) {
// send system event to actors subscribed to all topics
if let Some(subs) = self.subs.get(&All.into()) {
Expand Down Expand Up @@ -187,8 +177,6 @@ impl Actor for EventsChannel {
}

impl Receive<ChannelMsg<SystemEvent>> for EventsChannel {
type Msg = ChannelMsg<SystemEvent>;

fn receive(&mut self, ctx: &ChannelCtx<SystemEvent>, msg: Self::Msg, sender: Sender) {
// Publish variant uses specialized EventsChannel Receive
// All other variants use the wrapped Channel (self.0) Receive(s)
Expand All @@ -202,8 +190,6 @@ impl Receive<ChannelMsg<SystemEvent>> for EventsChannel {
}

impl Receive<Publish<SystemEvent>> for EventsChannel {
type Msg = ChannelMsg<SystemEvent>;

fn receive(
&mut self,
ctx: &ChannelCtx<SystemEvent>,
Expand Down
2 changes: 0 additions & 2 deletions src/system/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,6 @@ impl Actor for ShutdownActor {
}

impl Receive<ActorTerminated> for ShutdownActor {
type Msg = SystemEvent;

fn receive(
&mut self,
ctx: &Context<Self::Msg>,
Expand Down
4 changes: 0 additions & 4 deletions tests/actors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ impl Actor for Counter {
}

impl Receive<TestProbe> for Counter {
type Msg = CounterMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, msg: TestProbe, _sender: Sender) {
self.probe = Some(msg)
}
}

impl Receive<Add> for Counter {
type Msg = CounterMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: Add, _sender: Sender) {
self.count += 1;
if self.count == 1_000_000 {
Expand Down
16 changes: 0 additions & 16 deletions tests/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,13 @@ impl Actor for Subscriber {
}

impl Receive<TestProbe> for Subscriber {
type Msg = SubscriberMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, msg: TestProbe, _sender: Sender) {
msg.0.event(());
self.probe = Some(msg);
}
}

impl Receive<SomeMessage> for Subscriber {
type Msg = SubscriberMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: SomeMessage, _sender: Sender) {
self.probe.as_ref().unwrap().0.event(());
}
Expand Down Expand Up @@ -167,16 +163,12 @@ impl Actor for DumbActor {
}

impl Receive<Panic> for DumbActor {
type Msg = DumbActorMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: Panic, _sender: Sender) {
panic!("// TEST PANIC // TEST PANIC // TEST PANIC //");
}
}

impl Receive<SomeMessage> for DumbActor {
type Msg = DumbActorMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: SomeMessage, _sender: Sender) {

// Intentionally left blank
Expand Down Expand Up @@ -222,17 +214,13 @@ impl Actor for EventSubscriber {
}

impl Receive<TestProbe> for EventSubscriber {
type Msg = EventSubscriberMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, msg: TestProbe, _sender: Sender) {
msg.0.event(());
self.probe = Some(msg);
}
}

impl Receive<SystemEvent> for EventSubscriber {
type Msg = EventSubscriberMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, msg: SystemEvent, _sender: Sender) {
match msg {
SystemEvent::ActorCreated(created) => {
Expand Down Expand Up @@ -311,17 +299,13 @@ impl Actor for DeadLetterSub {
}

impl Receive<TestProbe> for DeadLetterSub {
type Msg = DeadLetterSubMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, msg: TestProbe, _sender: Sender) {
msg.0.event(());
self.probe = Some(msg);
}
}

impl Receive<DeadLetter> for DeadLetterSub {
type Msg = DeadLetterSubMsg;

fn receive(&mut self, _ctx: &Context<Self::Msg>, _msg: DeadLetter, _sender: Sender) {
self.probe.as_ref().unwrap().0.event(());
}
Expand Down
8 changes: 0 additions & 8 deletions tests/scheduling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ impl Actor for ScheduleOnce {
}

impl Receive<TestProbe> for ScheduleOnce {
type Msg = ScheduleOnceMsg;

fn receive(&mut self, ctx: &Context<ScheduleOnceMsg>, msg: TestProbe, _sender: Sender) {
self.probe = Some(msg);
// reschedule an Empty to be sent to myself()
Expand All @@ -41,8 +39,6 @@ impl Receive<TestProbe> for ScheduleOnce {
}

impl Receive<SomeMessage> for ScheduleOnce {
type Msg = ScheduleOnceMsg;

fn receive(&mut self, _ctx: &Context<ScheduleOnceMsg>, _msg: SomeMessage, _sender: Sender) {
self.probe.as_ref().unwrap().0.event(());
}
Expand Down Expand Up @@ -93,8 +89,6 @@ impl Actor for ScheduleRepeat {
}

impl Receive<TestProbe> for ScheduleRepeat {
type Msg = ScheduleRepeatMsg;

fn receive(&mut self, ctx: &Context<Self::Msg>, msg: TestProbe, _sender: Sender) {
self.probe = Some(msg);
// schedule Message to be repeatedly sent to myself
Expand All @@ -111,8 +105,6 @@ impl Receive<TestProbe> for ScheduleRepeat {
}

impl Receive<SomeMessage> for ScheduleRepeat {
type Msg = ScheduleRepeatMsg;

fn receive(&mut self, ctx: &Context<Self::Msg>, _msg: SomeMessage, _sender: Sender) {
if self.counter == 5 {
ctx.cancel_schedule(self.schedule_id.unwrap());
Expand Down
Loading

0 comments on commit 113178b

Please sign in to comment.