zbus::message

Struct Message

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

A D-Bus Message.

The contents of the message are stored in serialized format. To get the body of the message, use the Message::body method, and use Body methods to deserialize it. 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 deserialize the body (that you get using Message::body) to zvariant::OwnedFd if you want to keep the FDs around after the containing message is dropped.

Implementations§

Source§

impl Message

Source

pub fn method_call<'b, 'p: 'b, 'm: 'b, P, M>( path: P, method_name: M, ) -> Result<Builder<'b>>
where P: TryInto<ObjectPath<'p>>, M: TryInto<MemberName<'m>>, P::Error: Into<Error>, M::Error: Into<Error>,

Create a builder for a message of type Type::MethodCall.

Source

pub fn signal<'b, 'p: 'b, 'i: 'b, 'm: 'b, P, I, M>( path: P, iface: I, signal_name: M, ) -> Result<Builder<'b>>
where P: TryInto<ObjectPath<'p>>, I: TryInto<InterfaceName<'i>>, M: TryInto<MemberName<'m>>, P::Error: Into<Error>, I::Error: Into<Error>, M::Error: Into<Error>,

Create a builder for a message of type Type::Signal.

Source

pub fn method_return(reply_to: &Header<'_>) -> Result<Builder<'static>>

Create a builder for a message of type Type::MethodReturn.

Source

pub fn error<'b, 'e: 'b, E>( reply_to: &Header<'_>, name: E, ) -> Result<Builder<'b>>
where E: TryInto<ErrorName<'e>>, E::Error: Into<Error>,

Create a builder for a message of type Type::Error.

Source

pub unsafe fn from_bytes(bytes: Data<'static, 'static>) -> Result<Self>

Create a message from bytes.

Note: Since the message is not constructed by zbus, the receive sequence, which can be acquired from Message::recv_position, is not applicable and hence set to 0.

§Safety

This method is unsafe as bytes may have an invalid encoding.

Source

pub fn primary_header(&self) -> &PrimaryHeader

Source

pub fn header(&self) -> Header<'_>

The message header.

Source

pub fn message_type(&self) -> Type

The message type.

Source

pub fn body(&self) -> Body

The body that you can deserialize using Body::deserialize.

§Example
let send_body = (7i32, (2i32, "foo"), vec!["bar"]);
let message = Message::method_call("/", "ping")?
    .destination("zbus.test")?
    .interface("zbus.test")?
    .build(&send_body)?;
let header = message.header();
let body = message.body();
let body: zbus::zvariant::Structure = body.deserialize()?;
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_body = Message::method_return(&header)?.build(&body)?.body();
let reply_value : (i32, (i32, &str), Vec<String>) = reply_body.deserialize()?;

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

pub fn data(&self) -> &Data<'static, 'static>

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

Source

pub fn recv_position(&self) -> Sequence

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§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<InterfacesAdded> for Message

Source§

fn from(signal: InterfacesAdded) -> Self

Converts to this type from the input type.
Source§

impl From<InterfacesRemoved> for Message

Source§

fn from(signal: InterfacesRemoved) -> Self

Converts to this type from the input type.
Source§

impl From<Message> for Error

Source§

fn from(message: Message) -> Error

Converts to this type from the input type.
Source§

impl From<NameAcquired> for Message

Source§

fn from(signal: NameAcquired) -> Self

Converts to this type from the input type.
Source§

impl From<NameLost> for Message

Source§

fn from(signal: NameLost) -> Self

Converts to this type from the input type.
Source§

impl From<NameOwnerChanged> for Message

Source§

fn from(signal: NameOwnerChanged) -> Self

Converts to this type from the input type.
Source§

impl From<PropertiesChanged> for Message

Source§

fn from(signal: PropertiesChanged) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T