#D-Bus #DBus #libdbus

sys libdbus-sys

FFI bindings to libdbus

6 releases

0.1.5 Jan 9, 2019
0.1.4 Oct 12, 2018
0.1.3 Mar 5, 2018
0.1.2 Dec 5, 2017
0.1.0 Jun 24, 2017

#13 in Unix APIs

Download history 1741/week @ 2019-01-25 1805/week @ 2019-02-01 1744/week @ 2019-02-08 1471/week @ 2019-02-15 1577/week @ 2019-02-22 1365/week @ 2019-03-01 1698/week @ 2019-03-08 1765/week @ 2019-03-15 1718/week @ 2019-03-22 2468/week @ 2019-03-29 1825/week @ 2019-04-05 2384/week @ 2019-04-12 1571/week @ 2019-04-19 1978/week @ 2019-04-26 1604/week @ 2019-05-03

6,576 downloads per month
Used in 55 crates (1 directly)


263 lines

A D-Bus binding for Rust.

Current state of the dbus crate: Slowly maturing. Most stuff you need should be working:

  • Connect to system or session bus
  • Messages send/receive (method calls, method returns, signals, errors)
  • Message get/append arguments (through either generics, trait objects or enums), all types (including Unix Fd). See argument guide.
  • Build server side trees, with introspection and method dispatch (boxed closures)
  • Properties, on both client and server sides (set/get/getall methods, signals)
  • Optional async API (for poll-based mainloops, e g mio)

API Documentation is here. If you have further questions or comments, filing an issue with your question is fine.

Additional crates

  • libdbus-sys contains the raw FFI bindings to libdbus.
  • dbus-codegen installs a binary tool which generates Rust code from D-Bus XML introspection data.
  • dbus-tokio integrates D-Bus with Tokio.

All these crates are less tested and less mature than the main "dbus" crate.



This example opens a connection to the session bus and asks for a list of all names currently present.

let c = Connection::get_private(BusType::Session)?;
let m = Message::new_method_call("org.freedesktop.DBus", "/", "org.freedesktop.DBus", "ListNames")?;
let r = c.send_with_reply_and_block(m, 2000)?;
let arr: Array<&str, _>  = r.get1()?;
for name in arr { println!("{}", name); }

You can try a similar example by running:

cargo run --example client


This example grabs the com.example.dbustest bus name, registers the /hello path and adds a method which returns a string. It then listens for incoming D-Bus events and handles them accordingly.

let c = Connection::get_private(BusType::Session)?;
c.register_name("com.example.dbustest", NameFlag::ReplaceExisting as u32)?;
let f = Factory::new_fn::<()>();
let tree = f.tree(()).add(f.object_path("/hello", ()).introspectable().add(
    f.interface("com.example.dbustest", ()).add_m(
        f.method("Hello", (), |m| {
            let n: &str = m.msg.read1()?;
            let s = format!("Hello {}!", n);
tree.set_registered(&c, true)?;
loop { c.incoming(1000).next(); }

You can try a similar example (which has more comments) by running:

cargo run --example server

Or a more advanced server example:

cargo run --example adv_server


There are two examples of getting properties in the examples directory, one which uses the newer arg style and one that uses the older MessageItem style. See:

cargo run --example properties
cargo run --example properties_msgitem

For an extended example, which also uses non-panicking error handling, see



Libdbus 1.6 or higher, and latest stable release of Rust. If you run Ubuntu, this translates to Ubuntu 14.04 or later, having the libdbus-1-dev package installed while building, and the libdbus-1-3 package installed while running.

However, if you enable the feature no-string-validation, you might be able to build and run with older versions of the D-Bus library. This feature skips an extra check that a specific string (e g a Path, ErrorName etc) conforms to the D-Bus specification, which might also make things a tiny bit faster. But - if you do so, and then actually send invalid strings to the D-Bus library, you might get a panic instead of a proper error.


Apache 2.0 / MIT dual licensed.


  • links dbus