Struct service_io::message::Message
source · [−]pub struct Message {
pub user: String,
pub service_name: String,
pub args: Vec<String>,
pub body: String,
pub attached_data: HashMap<String, Vec<u8>>,
}
Expand description
Common data shared among input/output/services.
This is the language service-io
talk.
Each input/output/service understand this structure.
Example
use service_io::message::Message;
let request = Message::default()
.user("user_01")
.service_name("my_service")
.args(["arg0", "arg1", "arg2", "this is arg3"])
.body("body of the message")
.attach([
("file1.txt", b"content data".to_vec()),
("file2.txt", b"1234".to_vec())
]);
Fields
user: String
The user this message is related to. If the message is in the input side, this user means the originator of the message. If the message is in the output side, this user means the recipient of the message.
service_name: String
The service name this message going to/come from. The value of this field should match to any name used for register services.
See also: Engine::add_service()
args: Vec<String>
Arguments of the message. Each service implementation will understand these values in their own way.
body: String
Main body of the message. Each service implementation will understand this value in their own way.
attached_data: HashMap<String, Vec<u8>>
Attached content of the message. Each service implementation will understand these values in their own way.
Implementations
sourceimpl Message
impl Message
sourcepub fn response(message: &Message) -> Message
pub fn response(message: &Message) -> Message
Sugar to perform a response of a received message.
Creates an empty message with same Message::user
and Message::service_name
as the passed message.
Example
use service_io::message::Message;
let request = Message::default()
.user("user_01")
.service_name("my_service")
.body("1234");
let response = Message::response(&request);
// Name and service_name are copied
assert_eq!(request.user, response.user);
assert_eq!(request.service_name, response.service_name);
// But other fields as body are not copied.
assert_ne!(request.body, response.body);
sourcepub fn service_name(self, service_name: impl Into<String>) -> Self
pub fn service_name(self, service_name: impl Into<String>) -> Self
Set a service name for the message
sourcepub fn args<S: Into<String>>(self, args: impl IntoIterator<Item = S>) -> Self
pub fn args<S: Into<String>>(self, args: impl IntoIterator<Item = S>) -> Self
Set args for the message
Trait Implementations
sourceimpl PartialEq<Message> for Message
impl PartialEq<Message> for Message
impl StructuralPartialEq for Message
Auto Trait Implementations
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnwindSafe for Message
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> IntoOption<T> for T
impl<T> IntoOption<T> for T
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more