actor!() { /* proc-macro */ }Expand description
Genereate actor struct and inner methods
§Arguments
actor_struct_name- Name of the actor structmessage_type- Message struct that the actor will receiveresource_struct- Resource struct that the actor will usehandle_message- Method that will handle the messagepre_start- Method that will be called before the actor startspost_stop- Method that will be called after the actor stopspre_restart- Method that will be called before the actor restartspost_restart- Method that will be called after the actor restartskill_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
);