use std::fmt; use std::fmt::Debug; use std::marker::PhantomData; use riker_macros::actor; #[test] fn impls_test() { let en = NewActorMsg::U32(1); let actor = ActorRef:: { x: PhantomData }; } #[actor(String, u32)] #[derive(Clone, Default)] struct NewActor; impl Actor for NewActor { type Msg = NewActorMsg; fn handle(&mut self, ctx: &Context, msg: Self::Msg, sender: Option) { println!("handling.."); self.receive(ctx, msg, sender); } } impl Receive for NewActor { type Msg = NewActorMsg; fn receive(&mut self, ctx: &Context, msg: u32, sender: Option) { println!("u32"); } } impl Receive for NewActor { type Msg = NewActorMsg; fn receive(&mut self, ctx: &Context, msg: String, sender: Option) { println!("String"); } } struct BasicActorRef; type Context = Option; trait Actor: Send + 'static { type Msg: Message; /// Invoked when an actor is being started by the system. /// /// Any initialization inherent to the actor's role should be /// performed here. /// /// Panics in `pre_start` do not invoke the /// supervision strategy and the actor will be terminated. fn pre_start(&mut self) {} /// Invoked after an actor has started. /// /// Any post initialization can be performed here, such as writing /// to a log file, emmitting metrics. /// /// Panics in `post_start` follow the supervision strategy. fn post_start(&mut self) {} /// Invoked after an actor has been stopped. fn post_stop(&mut self) {} fn sys_receive(&mut self, msg: Self::Msg) {} fn handle(&mut self, ctx: &Context, msg: Self::Msg, sender: Option); } trait Receive { type Msg: Message; fn receive(&mut self, ctx: &Context, msg: Msg, sender: Option); } type BoxedTell = Box + Send + 'static>; trait Tell: Send + 'static { fn tell(&self, msg: T, sender: Option); fn box_clone(&self) -> BoxedTell; } impl fmt::Debug for BoxedTell { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Tell") } } impl fmt::Display for BoxedTell { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Tell") } } impl Clone for BoxedTell { fn clone(&self) -> Self { self.box_clone() } } trait Message: Debug + Clone + Send + 'static {} impl Message for T {} #[derive(Clone)] struct ActorRef { x: PhantomData, } impl ActorRef { fn send_msg(&self, msg: T, sender: Option) { let a = NewActor::default(); // a.receive(msg); } }