pub struct Msg { /* private fields */ }Expand description
The actual payload received by actors inside a Mail enum construct
Implementations§
Source§impl Msg
impl Msg
Sourcepub fn new(content: Option<Vec<u8>>, from: &str, to: &str) -> Self
pub fn new(content: Option<Vec<u8>>, from: &str, to: &str) -> Self
Construct a new message with binary content with from and to addresses
Sourcepub fn with_binary_content(content: Option<Vec<u8>>) -> Self
pub fn with_binary_content(content: Option<Vec<u8>>) -> Self
Update the message with binary content
Sourcepub fn from_text(content: &str) -> Self
pub fn from_text(content: &str) -> Self
Create a msg with content as text to an actor(actor1) in the local system
§Example
use arrows::send;
use arrows::Msg;
let m = Msg::with_text("A good will message");
send!("actor1", m);
Examples found in repository?
4fn main() {
5 let m1 = Msg::from_text("Message to new_actor");
6 let m2 = Msg::from_text("Message to new_actor");
7 let m3 = Msg::from_text("Message to new_actor");
8
9 send!("demo_actor", (m1, m2, m3));
10
11 let mut m4 = Msg::from_text("Message to another_actor");
12
13 //Impersonate sender as "new_actor"
14 m4.set_from(&Addr::new("demo_actor"));
15
16 send!("another_actor", m4);
17}More examples
5pub fn main() {
6 let m1 = Msg::from_text("Message to actor1");
7 let m2 = Msg::from_text("Message to actor1");
8 let m3 = Msg::from_text("Message to actor2");
9 let m4 = Msg::from_text("Message to actor1");
10 let m5 = Msg::from_text("Message to actor1");
11 send!("actor1", (m1, m2), "actor2", (m3), "actor1", (m4, m5));
12
13 let remote_addr1 = Addr::remote("actor1", "10.10.10.10:7171");
14 let remote_addr2 = Addr::remote("actor2", "11.11.11.11:8181");
15
16 let m1 = Msg::from_text("Message to remote actor1");
17 let m2 = Msg::from_text("Message to remote actor1");
18 let m3 = Msg::from_text("Message to remote actor2");
19 let m4 = Msg::from_text("Message to remote actor2");
20
21 send!(remote_addr1, (m1, m2), remote_addr2, (m3, m4));
22}Sourcepub fn with_text(content: &str, from: &str, to: &str) -> Self
pub fn with_text(content: &str, from: &str, to: &str) -> Self
Construct a text message with from and to addresses
Sourcepub fn as_text(&self) -> Option<&str>
pub fn as_text(&self) -> Option<&str>
Get the content of msg as text. In case - binary content being actually binary this would not be helpful.
Sourcepub fn is_command(&self) -> bool
pub fn is_command(&self) -> bool
Is the message actually a command?
Sourcepub fn command_equals(&self, action: Action) -> bool
pub fn command_equals(&self, action: Action) -> bool
Command action equality check
Sourcepub fn as_bytes(&self) -> Vec<u8> ⓘ
pub fn as_bytes(&self) -> Vec<u8> ⓘ
The message as bytes - irrespective of whether content is text or actual binary blob. Empty byte vec - if can not be serialized
Sourcepub fn text_reply(&mut self, reply: &str)
pub fn text_reply(&mut self, reply: &str)
Construct a text reply with content as string and message direction reversed
Sourcepub fn update_text_content(&mut self, reply: &str)
pub fn update_text_content(&mut self, reply: &str)
Update the content of the message - text
Sourcepub fn with_content_and_to(&mut self, new_content: Vec<u8>, new_to: &str)
pub fn with_content_and_to(&mut self, new_content: Vec<u8>, new_to: &str)
Set new binary content and new local recipient actor address
Sourcepub fn with_content(&mut self, new_content: Vec<u8>)
pub fn with_content(&mut self, new_content: Vec<u8>)
Set the binary content of the message
Sourcepub fn set_recipient_addr(&mut self, addr: &Addr)
pub fn set_recipient_addr(&mut self, addr: &Addr)
Set the recipient address of the message
Sourcepub fn set_recipient(&mut self, new_to: &str)
pub fn set_recipient(&mut self, new_to: &str)
Set the recipient identifier as string literal
Sourcepub fn set_recipient_ip(&mut self, new_to_ip: &str)
pub fn set_recipient_ip(&mut self, new_to_ip: &str)
Set the recipient actor’s IP - used in remoting
Sourcepub fn set_recipient_port(&mut self, new_port: u16)
pub fn set_recipient_port(&mut self, new_port: u16)
Set the recipient port
Sourcepub fn get_recipient_port(&self) -> u16
pub fn get_recipient_port(&self) -> u16
Get the port of the recipient actor - used for remote messaging
Sourcepub fn binary_reply(&mut self, reply: Option<Vec<u8>>)
pub fn binary_reply(&mut self, reply: Option<Vec<u8>>)
Reverse the message direction - ‘to’ to ‘from’ or other way
Sourcepub fn binary_content(&self) -> Option<Vec<u8>>
pub fn binary_content(&self) -> Option<Vec<u8>>
Get the binary content - the message remains intact
Sourcepub fn binary_content_out(&mut self) -> Option<Vec<u8>>
pub fn binary_content_out(&mut self) -> Option<Vec<u8>>
If the message content is binary blob - get it Would take content out - leaving message content to a None
Sourcepub fn id_as_string(&self) -> String
pub fn id_as_string(&self) -> String
Get the id as string. Required because unique ids overflow i64 range supported by the backing store
Sourcepub fn set_from(&mut self, from: &Addr)
pub fn set_from(&mut self, from: &Addr)
Set the from address of a message - specific usage while sending out actor message processing outcome
Examples found in repository?
4fn main() {
5 let m1 = Msg::from_text("Message to new_actor");
6 let m2 = Msg::from_text("Message to new_actor");
7 let m3 = Msg::from_text("Message to new_actor");
8
9 send!("demo_actor", (m1, m2, m3));
10
11 let mut m4 = Msg::from_text("Message to another_actor");
12
13 //Impersonate sender as "new_actor"
14 m4.set_from(&Addr::new("demo_actor"));
15
16 send!("another_actor", m4);
17}