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

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);

Set a user for the message

Set a service name for the message

Set args for the message

Set a body for the message

Set attached data for the message

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more