Struct tokio_dbus::Connection

source ·
pub struct Connection { /* private fields */ }
Expand description

An asynchronous D-Bus client.

Implementations§

source§

impl Connection

source

pub async fn session_bus() -> Result<Self>

Shorthand for connecting the client to the system bus using the default configuration.

source

pub async fn system_bus() -> Result<Self>

Shorthand for connecting the client to the system bus using the default configuration.

source

pub async fn wait(&mut self) -> Result<()>

Wait for the next incoming message on this connection.

This is the main entry of this connection, and is required to call to have it make progress when passing D-Bus messages.

If you just want to block while sending messages, use flush() instead.

§Examples
use tokio_dbus::{Connection, Message};

let mut c = Connection::session_bus().await?;
c.wait().await?;
let message: Message<'_> = c.last_message()?;
source

pub async fn wait_no_deferred(&mut self) -> Result<()>

Wait for the next incoming message on this connection ignoring messages that have been deferred through RecvBuf::defer.

§Examples
use tokio_dbus::{Connection, Message};

let mut c = Connection::session_bus().await?;
c.wait_no_deferred().await?;
let message: Message<'_> = c.last_message()?;
source

pub async fn flush(&mut self) -> Result<()>

Flush all outgoing messages and return when the send buffer is empty.

§Examples
use tokio_dbus::Connection;

let mut c = Connection::session_bus().await?;
c.flush().await?;
source

pub fn method_call<'a>( &mut self, path: &'a ObjectPath, member: &'a str ) -> Message<'a>

Construct a new Message corresponding to a method call.

source

pub fn write_message(&mut self, message: Message<'_>) -> Result<()>

Write a message to the send buffer.

This can be used to queue messages to be sent during the next call to wait(). To both receive and send in parallel, see the buffers() method.

source

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

Read the last message buffered.

§Errors

In case there is no message buffered.

source

pub fn buffers(&mut self) -> (&RecvBuf, &mut SendBuf, &mut BodyBuf)

Access the underlying buffers of the connection.

The RecvBuf instance is used to access messages received after a call to wait(), through the RecvBuf::last_message().

The returned BodyBuf is the internal buffer that the client uses to construct message bodies. It is empty when it’s returned.

This is useful, because it permits using all parts of the connection without running into borrowing issues.

For example, this wouldn’t work:

use tokio_dbus::{Connection, Message};

let mut c = Connection::session_bus().await?;
c.wait().await?;
let message: Message<'_> = c.last_message()?;
let m = message.method_return();
c.write_message(m);

Because calling write_message() needs mutable access to the Connection.

We can address this by using buffers():

use tokio_dbus::{Connection, Message};

let mut c = Connection::session_bus().await?;
c.wait().await?;

let (recv, send, body) = c.buffers();

let message: Message<'_> = recv.last_message()?;
let m = message.method_return(send.next_serial()).with_body(body);

send.write_message(m);
source

pub async fn request_name( &mut self, name: &str, flags: NameFlag ) -> Result<NameReply>

Request the given well-known name.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.