logo
pub struct Message { /* private fields */ }
Expand description

A D-Bus Message.

The content of the message are stored in serialized format. To deserialize the body of the message, use the body method. You may also access the header and other details with the various other getters.

Also provided are constructors for messages of different types. These will mainly be useful for very advanced use cases as typically you will want to create a message for immediate dispatch and hence use the API provided by Connection, even when using the low-level API.

Note: The message owns the received FDs and will close them when dropped. You can call take_fds after deserializing to RawFD using body if you want to take the ownership.

Implementations

Create a message of type MessageType::MethodCall.

Create a message of type MessageType::Signal.

Create a message of type MessageType::MethodReturn.

Create a message of type MessageType::MethodError.

Take ownership of the associated file descriptors in the message.

When a message is received over a AF_UNIX socket, it may contain associated FDs. To prevent the message from closing those FDs on drop, call this method that returns all the received FDs with their ownership.

This function is Unix-specific.

Note: the message will continue to reference the files, so you must keep them open for as long as the message itself.

The signature of the body.

Note: While zbus treats multiple arguments as a struct (to allow you to use the tuple syntax), D-Bus does not. Since this method gives you the signature expected on the wire by D-Bus, the trailing and leading STRUCT signature parenthesis will not be present in case of multiple arguments.

Deserialize the header.

Note: prefer using the direct access methods if possible; they are more efficient.

Deserialize the fields.

Note: prefer using the direct access methods if possible; they are more efficient.

The message type.

The object to send a call to, or the object a signal is emitted from.

The interface to invoke a method call on, or that a signal is emitted from.

The member, either the method name or signal name.

The serial number of the message this message is a reply to.

Deserialize the body (without checking signature matching).

Deserialize the body using the contained signature.

Example
let send_body = (7i32, (2i32, "foo"), vec!["bar"]);
let message = Message::method(None::<&str>, Some("zbus.test"), "/", Some("zbus.test"), "ping", &send_body)?;
let body : zvariant::Structure = message.body()?;
let fields = body.fields();
assert!(matches!(fields[0], zvariant::Value::I32(7)));
assert!(matches!(fields[1], zvariant::Value::Structure(_)));
assert!(matches!(fields[2], zvariant::Value::Array(_)));

let reply_msg = Message::method_reply(None::<&str>, &message, &body)?;
let reply_value : (i32, (i32, &str), Vec<String>) = reply_msg.body()?;

assert_eq!(reply_value.0, 7);
assert_eq!(reply_value.2.len(), 1);

Get a reference to the byte encoding of the message.

Get a reference to the byte encoding of the body of the message.

Get the receive ordering of a message.

This may be used to identify how two events were ordered on the bus. It only produces a useful ordering for messages that were produced by the same zbus::Connection.

This is completely unrelated to the serial number on the message, which is set by the peer and might not be ordered at all.

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

The type of value produced by the sink when an error occurs.

Attempts to prepare the Sink to receive a value. Read more

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more

Flush any remaining output from this sink. Read more

Flush any remaining output and close this sink, if necessary. Read more

The type of value produced by the sink when an error occurs.

Attempts to prepare the Sink to receive a value. Read more

Begin the process of sending a value to the sink. Each call to this function must be preceded by a successful call to poll_ready which returned Poll::Ready(Ok(())). Read more

Flush any remaining output from this sink. Read more

Flush any remaining output and close this sink, if necessary. 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

Calls U::from(self).

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

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

Converts the given value to a String. 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