xan_actor

Macro actor

Source
actor!() { /* proc-macro */ }
Expand description

Genereate actor struct and inner methods

§Arguments

  • actor_struct_name - Name of the actor struct
  • message_struct - Message struct that the actor will receive
  • resource_struct - Resource struct that the actor will use
  • handle_message - Method that will handle the message
  • pre_start - Method that will be called before the actor starts
  • post_stop - Method that will be called after the actor stops
  • pre_restart - Method that will be called before the actor restarts
  • post_restart - Method that will be called after the actor restarts
  • kill_in_error - kill the actor if an error occurs - TODO: not supported yet

§Example

use xan_actor::{actor, actor_system, recv_res, send_msg};

actor_system!(); // It always needs to be called once in lib.rs or main.rs

actor!( TestActor, struct Message { pub message: String, }, struct TestActorResource { pub name: String, }, fn handle_message(&self, message: Message) -> String { message.message }, fn pre_start(&mut self) {}, fn post_stop(&mut self) {}, fn pre_restart(&mut self) {}, fn post_restart(&mut self) {}, true );