This crate provides the main API you will use to interact with D-Bus from Rust. It takes care of the establishment of a connection, the creation, sending and receiving of different kind of D-Bus messages (method calls, signals etc) for you.
zbus crate is currently Linux-specific[^otheros].
Getting Started
The best way to get started with zbus is the book, where we start with basic D-Bus concepts and explain with code samples, how zbus makes D-Bus easy.
Example code
Client
This code display a notification on your Freedesktop.org-compatible OS:
use HashMap;
use Error;
use dbus_proxy;
use Value;
Server
A simple service that politely greets whoever calls its SayHello
method:
use Error;
use ;
;
You can use the following command to test it:
Asynchronous API
Runtime-agnostic async/await-compatible API for both (not so) low-level message handling and high-level client-side proxy is also provided. High-level server-side API coming soon.
Compatibility with async runtimes
zbus is runtime-agnostic and should work out of the box with different Rust async runtimes. However, in order to achieve that, zbus spawns a thread per connection to handle various internal tasks. If that is something you would like to avoid, you need to:
- disable the
internal-executor
feature (which is a default feature). - Ensure the internal executor keeps ticking continuously.
[^otheros]: Support for other OS exist, but it is not supported to the same extent. D-Bus clients in javascript (running from any browser) do exist though. And zbus may also be working from the browser sometime in the future too, thanks to Rust 🦀 and WebAssembly 🕸.