zbus
This is the main subcrate of the zbus project, that provides the API to interact with D-Bus. 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.
Status: Stable.
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 ;
use ;
use Value;
// Although we use `async-std` here, you can use any async runtime of choice.
async
Server
A simple service that politely greets whoever calls its SayHello
method:
use ;
use ;
// Although we use `async-std` here, you can use any async runtime of choice.
async
You can use the following command to test it:
Blocking API
While zbus is primarily asynchronous (since 2.0), blocking wrappers are provided for convenience.
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:
- Use
ConnectionBuilder
and disable theinternal_executor
flag. - Ensure the internal executor keeps ticking continuously.
Moreover, by default zbus makes use of async-io
for all I/O, which also launches its own thread
to run its own internal executor.
Special tokio support
Since tokio
is the most popular async runtime, zbus provides an easy way to enable tight
integration with it without you having to worry about any of the above: Enabling the tokio
feature
and disabling the default async-io
feature:
# Sample Cargo.toml snippet.
[]
= { = "2", = false, = ["tokio"] }
That's it! No threads launched behind your back by zbus (directly or indirectly) now and no need to tick any executors etc. 😼
Note: On Windows, the async-io
feature is currently required for UNIX domain socket support,
see the corresponding tokio issue on GitHub.