Skip to main content

MessageBuf

Struct MessageBuf 

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

An owned D-Bus message.

This is the owned variant of a Message, to convert to a Message, use MessageBuf::borrow.

Implementations§

Source§

impl MessageBuf

Source

pub fn method_call( path: Box<ObjectPath>, member: Box<str>, serial: Serial, ) -> Self

Construct a method call.

§Examples
use tokio_dbus::{Message, ObjectPath, MessageBuf, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = Message::method_call(PATH, "Hello", send.next_serial()).to_owned();
let m2 = MessageBuf::method_call(PATH.into(), "Hello".into(), m.serial());
assert_eq!(m, m2);
Source

pub fn method_return(self, serial: Serial) -> Self

Convert this message into a MessageKind::MethodReturn message with an empty body where the reply serial matches that of the current message.

The send argument is used to populate the next serial number.

§Examples
use tokio_dbus::{Message, MessageKind, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.method_call(PATH, "Hello")
    .with_sender("se.tedro.DBusExample")
    .with_destination("org.freedesktop.DBus")
    .to_owned();

let m2 = m.clone().method_return(send.next_serial());
assert!(matches!(m2.kind(), MessageKind::MethodReturn { .. }));

assert_eq!(m.sender(), m2.destination());
assert_eq!(m.destination(), m2.sender());
Source

pub fn signal(path: Box<ObjectPath>, member: Box<str>, serial: Serial) -> Self

Construct a signal MessageBuf.

§Examples
use tokio_dbus::{MessageBuf, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.signal(PATH, "Hello").to_owned();
let m2 = MessageBuf::signal(PATH.into(), "Hello".into(), m.serial());
assert_eq!(m, m2);
Source

pub fn error(self, error_name: Box<str>, serial: Serial) -> Self

Convert this message into a MessageKind::Error message with an empty body where the reply serial matches that of the current message.

§Examples
use tokio_dbus::{Message, MessageKind, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.method_call(PATH, "Hello")
    .with_sender("se.tedro.DBusExample")
    .with_destination("org.freedesktop.DBus");

let m2 = m.clone().error("org.freedesktop.DBus.UnknownMethod", send.next_serial());
assert!(matches!(m2.kind(), MessageKind::Error { .. }));

assert_eq!(m.sender(), m2.destination());
assert_eq!(m.destination(), m2.sender());
Source

pub fn borrow(&self) -> Message<'_>

Borrow into a Message.

Source

pub fn kind(&self) -> MessageKind<'_>

Get the kind of the message.

§Examples
use tokio_dbus::{Message, MessageKind, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.method_call(PATH, "Hello");
assert!(matches!(m.kind(), MessageKind::MethodCall { .. }));

let m2 = m.error("org.freedesktop.DBus.UnknownMethod", send.next_serial());
assert!(matches!(m2.kind(), MessageKind::Error { .. }));
Source

pub fn with_body(self, body: BodyBuf) -> Self

Modify the body and signature of the message to match that of the provided body buffer.

§Examples
use tokio_dbus::{BodyBuf, MessageKind, ObjectPath, SendBuf, Signature};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();
let mut body = BodyBuf::new();

body.store("Hello World!");

let m = send.method_call(PATH, "Hello")
    .to_owned()
    .with_body(body);

assert!(matches!(m.kind(), MessageKind::MethodCall { .. }));
assert_eq!(m.signature(), Signature::STRING);
Source

pub fn body(&self) -> Body<'_>

Get a buffer to the body of the message.

§Examples
use tokio_dbus::{BodyBuf, MessageKind, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();
let mut body = BodyBuf::new();

body.store(42u32);
body.store("Hello World!");

let m = send.method_call(PATH, "Hello")
    .to_owned()
    .with_body(body);

assert!(matches!(m.kind(), MessageKind::MethodCall { .. }));
assert_eq!(m.signature(), "us");

let mut r = m.body();
assert_eq!(r.load::<u32>()?, 42);
assert_eq!(r.read::<str>()?, "Hello World!");
Source

pub fn serial(&self) -> Serial

Get the serial of the message.

§Examples
use tokio_dbus::{Message, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.method_call(PATH, "Hello");
let initial = m.serial();
let m2 = m.with_serial(send.next_serial());
assert_ne!(initial, m2.serial());
Source

pub fn with_serial(self, serial: Serial) -> Self

Modify the serial of the message.

§Examples
use tokio_dbus::{Message, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.method_call(PATH, "Hello");
let m2 = send.method_call(PATH, "Hello");
let m2 = m2.with_serial(m.serial());
assert_eq!(m.serial(), m2.serial());
Source

pub fn flags(&self) -> Flags

Get the flags of the message.

§Examples
use tokio_dbus::{Flags, Message, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.method_call(PATH, "Hello");
assert_eq!(m.flags(), Flags::default());

let m2 = m.with_flags(Flags::NO_REPLY_EXPECTED);
assert_eq!(m2.flags(), Flags::NO_REPLY_EXPECTED);
Source

pub fn with_flags(self, flags: Flags) -> Self

Modify the flags of the message.

§Examples
use tokio_dbus::{Flags, Message, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.method_call(PATH, "Hello");
assert_eq!(m.flags(), Flags::default());

let m2 = m.with_flags(Flags::NO_REPLY_EXPECTED);
assert_eq!(m2.flags(), Flags::NO_REPLY_EXPECTED);
Source

pub fn interface(&self) -> Option<&str>

Get the interface of the message.

§Examples
use tokio_dbus::{Message, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.method_call(PATH, "Hello").to_owned();
assert_eq!(m.interface(), None);

let m2 = m.with_interface("org.freedesktop.DBus".into());
assert_eq!(m2.interface(), Some("org.freedesktop.DBus"));
Source

pub fn with_interface(self, interface: Box<str>) -> Self

Modify the interface of the message.

§Examples
use tokio_dbus::{Message, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.method_call(PATH, "Hello").to_owned();
assert_eq!(m.interface(), None);

let m2 = m.with_interface("org.freedesktop.DBus".into());
assert_eq!(m2.interface(), Some("org.freedesktop.DBus"));
Source

pub fn destination(&self) -> Option<&str>

Get the destination of the message.

§Examples
use tokio_dbus::{Message, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.method_call(PATH, "Hello").to_owned();
assert_eq!(m.destination(), None);

let m2 = m.with_destination(":1.131".into());
assert_eq!(m2.destination(), Some(":1.131"));
Source

pub fn with_destination(self, destination: Box<str>) -> Self

Modify the destination of the message.

§Examples
use tokio_dbus::{Message, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.method_call(PATH, "Hello").to_owned();
assert_eq!(m.destination(), None);

let m2 = m.with_destination(":1.131".into());
assert_eq!(m2.destination(), Some(":1.131"));
Source

pub fn sender(&self) -> Option<&str>

Get the sender of the message.

§Examples
use tokio_dbus::{Message, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.method_call(PATH, "Hello").to_owned();
assert_eq!(m.destination(), None);

let m2 = m.with_sender(":1.131".into());
assert_eq!(m2.sender(), Some(":1.131"));
Source

pub fn with_sender(self, sender: Box<str>) -> Self

Modify the sender of the message.

§Examples
use tokio_dbus::{Message, ObjectPath, SendBuf};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.method_call(PATH, "Hello").to_owned();
assert_eq!(m.destination(), None);

let m2 = m.with_sender(":1.131".into());
assert_eq!(m2.sender(), Some(":1.131"));
Source

pub fn signature(&self) -> &Signature

Get the signature of the message.

§Examples
use tokio_dbus::{BodyBuf, ObjectPath, SendBuf, Signature};

const PATH: &ObjectPath = ObjectPath::new_const(b"/org/freedesktop/DBus");

let mut send = SendBuf::new();

let m = send.method_call(PATH, "Hello").to_owned();
assert_eq!(m.signature(), Signature::EMPTY);

let mut body = BodyBuf::new();
body.store("Hello World!");

let m2 = m.with_body(body);
assert_eq!(m2.signature(), Signature::STRING);

Trait Implementations§

Source§

impl Clone for MessageBuf

Source§

fn clone(&self) -> MessageBuf

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MessageBuf

Source§

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

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

impl Eq for MessageBuf

Source§

impl PartialEq for MessageBuf

Source§

fn eq(&self, other: &MessageBuf) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<Message<'_>> for MessageBuf

Source§

fn eq(&self, other: &Message<'_>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<MessageBuf> for Message<'_>

Available on crate feature alloc only.
Source§

fn eq(&self, other: &MessageBuf) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MessageBuf

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, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.