pub struct Message {
pub text: String,
pub starting_module: String,
pub request_topic: String,
pub response_topics: LinkedList<String>,
pub sender: String,
pub message_type: MessageType,
pub params: HashMap<String, String, RandomState>,
}Fields§
§text: String§starting_module: String§request_topic: String§response_topics: LinkedList<String>§sender: String§message_type: MessageType§params: HashMap<String, String, RandomState>Implementations§
Source§impl Message
impl Message
pub fn empty() -> Self
pub fn compress(&self) -> String
Sourcepub fn decompress(comp_str: &str) -> Result<Self, MessageCompressionError>
pub fn decompress(comp_str: &str) -> Result<Self, MessageCompressionError>
decompress
§Examples
use std::collections::{HashMap, LinkedList, VecDeque};
use std::io::Lines;
use alfred_core::message::{Message, MessageType};
const MESSAGE_SEPARATOR : char = 0x0 as char;
let decompressed = Message::decompress(format!("text{MESSAGE_SEPARATOR}module{MESSAGE_SEPARATOR}user.request{MESSAGE_SEPARATOR}module.response{MESSAGE_SEPARATOR}0123{MESSAGE_SEPARATOR}Text{MESSAGE_SEPARATOR}par1{MESSAGE_SEPARATOR}val1{MESSAGE_SEPARATOR}par2{MESSAGE_SEPARATOR}val2{MESSAGE_SEPARATOR}").as_str());
assert!(decompressed.is_ok());
let mut params = HashMap::new();
params.insert(String::from("par1"), String::from("val1"));
params.insert(String::from("par2"), String::from("val2"));
let message: Message = Message {
text: String::from("text"),
starting_module: String::from("module"),
request_topic: String::from("user.request"),
response_topics: LinkedList::from([String::from("module.response")]),
sender: String::from("0123"),
message_type: MessageType::Text,
params
};
assert_eq!(message, decompressed.unwrap());pub fn reply( &self, text: String, message_type: MessageType, ) -> Result<(String, Self), Error>
Trait Implementations§
impl Eq for Message
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more