tokio-dbus-codegen
Generate asynchronous D-Bus clients and servers from interface files at build time.
The generated code speaks in owned Rust types [String], [Vec], and
HashMap and tuples and is driven by a
tokio_dbus_runtime::Connection, which both crates a consumer needs to
depend on.
Using it from a build script
Add the generator as a build dependency and the runtime as a regular one:
[]
= "0.2.0"
[]
= "0.2.0"
Then write a build.rs which names the interface files to read and what to
generate for each interface in them:
Finally include the generated file:
include!;
What is generated
For an interface com.example.Example, a module example is generated
holding:
INTERFACEandMATCH_RULEconstants.- A
Signalenum with a variant per signal, which can be decoded from an incoming message and emitted from an outgoing one. Present whenever the interface has signals. - With
client(), anExamplestruct with anasyncmethod per D-Bus method, a getter and setter per property, andall_properties(). - With
server(), anExampleServertrait with anasyncmethod per D-Bus method and per property accessor, and adispatch()function which routes an incoming call to it.dispatch()also answersorg.freedesktop.DBus.Propertiesfor the interface.
Type mapping
| D-Bus | Rust |
|---|---|
y |
[u8] |
b |
[bool] |
n / q |
[i16] / [u16] |
i / u |
[i32] / [u32] |
x / t |
[i64] / [u64] |
d |
[f64] |
s |
[String] |
o |
ObjectPathBuf |
g |
SignatureBuf |
v |
Value |
aT |
Vec<T> |
a{KV} |
HashMap<K, V> |
(T1 T2) |
(T1, T2) |
Client methods take the borrowed form of each argument where borrowing is
free, so an s is passed as a [&str] and an as as a &[String].
Passing a file descriptor (h) is not supported.