1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
extern crate proc_macro;
extern crate quote;
/// Generate actor system struct and inner methods.
/// It contains LifeCycle, WhoisResponse struct too
/// Genereate actor struct and inner methods
/// # Arguments
/// * `actor_struct_name` - Name of the actor struct
/// * `message_type` - 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
/// ```rust
/// 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
/// );
/// ```
/// Send a message to an actor
/// # Arguments
/// * `actor_system` - Actor system that the actor belongs to
/// * `address` - Address of the actor
/// * `message` - Message to send
///
/// # Example
/// ```rust
/// use xan_actor::send_msg;
/// send_msg!(
/// &mut actor_system,
/// "test-actor".to_string(),
/// &"test".to_string()
/// );
/// ```
/// Receive a response from an actor
/// # Arguments
/// * `res_type` - Type of the response
/// * `response_rx` - Response receiver
///
/// # Example
/// ```rust
/// use xan_actor::{recv_res, send_msg};
/// let response_rx = send_msg!(
/// &mut actor_system,
/// "test-actor".to_string(),
/// &"test".to_string()
/// );
/// let response = recv_res!(
/// String,
/// response_rx
/// );
/// ```