use std::fmt; use std::fmt::Debug; use std::marker::PhantomData; use actors_macros::actor; #[test] fn impls_test() { let _msg = NewActorMsg::U32(1); let _actor = ActorRef:: { x: PhantomData }; // actor.tell(5, None); } // #[derive(Clone, Debug)] // enum NewActorMsg { // U32(u32), // String(String), // } #[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: Sender) { println!("handling.."); self.receive(ctx, msg, sender); } } impl Receive for NewActor { type Msg = NewActorMsg; fn receive(&mut self, _ctx: &Context, _msg: u32, _sender: Sender) { println!("u32"); } } impl Receive for NewActor { type Msg = NewActorMsg; fn receive(&mut self, _ctx: &Context, _msg: String, _sender: Sender) { println!("String"); } } struct BasicActorRef; type Sender = Option; 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: Sender); } trait Receive { type Msg: Message; fn receive(&mut self, ctx: &Context, msg: Msg, sender: Sender); } 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); // } // }