8 stable releases

2.3.1 Dec 16, 2021
2.3.0 Dec 12, 2021
2.2.0 Jul 27, 2021
2.1.0 Jan 31, 2021
1.1.0 Jun 30, 2020

#1236 in Asynchronous


Used in 2 crates

BSD-3-Clause

75KB
1.5K SLoC

dbus-async

A pure Rust written asynchronous DBus library.
Build status Latest version License Dependency status

Usage

Add this to your Cargo.toml:

[dependencies]
dbus-async = "~2.3.1"

You have to specify, which Tokio Runtime should be used.

  • For multi-threaded add this to your Cargo.toml:
    [dependencies.tokio]
    version = " ~1.15.0"
    features = ["rt-multi-thread"]
    
  • For single-threaded add this to your Cargo.toml:
    [dependencies.tokio]
    version = "~1.15.0"
    features = ["rt"]
    

Example

use dbus_async::DBus;
use dbus_message_parser::Message;
use std::convert::TryInto;

#[tokio::main]
async fn main() {
    let (dbus, _server_handle) = DBus::session(true)
        .await
        .expect("failed to get the DBus object");

    // Create a MethodCall.
    let msg = Message::method_call(
        "org.freedesktop.DBus".try_into().unwrap(),
        "/org/freedesktop/DBus".try_into().unwrap(),
        "org.freedesktop.DBus.Peer".try_into().unwrap(),
        "Ping".try_into().unwrap(),
    );

    // Send the message and get the return message.
    let return_msg = dbus.call(msg).await;

    // Print the return message.
    println!("{:?}", return_msg);
}

If you want to implement a DBus service and do not implement the dbus_async::Handler trait manually then use dbus-async-derive crate.

Features

Dependencies

~7.5MB
~126K SLoC