#dbus #ipc #zbus #type-safety

macro zbus-lockstep-macros

Macros to keep types in lockstep with DBus XML definitions

14 releases

new 0.5.2 Nov 29, 2025
0.5.1 Jun 24, 2025
0.5.0 Dec 2, 2024
0.4.4 Mar 18, 2024
0.3.1 Oct 2, 2023

#1471 in Procedural macros

Download history 57498/week @ 2025-08-09 50840/week @ 2025-08-16 56682/week @ 2025-08-23 72573/week @ 2025-08-30 61224/week @ 2025-09-06 62606/week @ 2025-09-13 59436/week @ 2025-09-20 64237/week @ 2025-09-27 65788/week @ 2025-10-04 65719/week @ 2025-10-11 70661/week @ 2025-10-18 70889/week @ 2025-10-25 61884/week @ 2025-11-01 61307/week @ 2025-11-08 68115/week @ 2025-11-15 60111/week @ 2025-11-22

262,484 downloads per month
Used in 127 crates (via atspi-common)

MIT license

68KB
954 lines

zbus-lockstep-macros

CI Maintenance crates-io api-docs

zbus-lockstep-macros extends zbus-lockstep to match the signature of signal types <T as zvariant::Type>::signature() with a corresponding signature from a DBus XML file more conveniently and succinctly.

Motivation

In the context of IPC over DBus, especially where there are multiple implementations of servers and/or clients communicating, it is necessary for each implementation to send what others expect and that expectations are in accordance with what is sent over the bus.

The XML protocol-descriptions may act as a shared frame of reference or "single source of all truth" for all implementers. Having a single point of reference helps all implementers meet expectations on protocol conformance.

Keeping the types you send over DBus in lockstep with currently valid protocol-descriptions will reduce chances of miscommunication or failure to communicate.

Use

Add zbus-lockstep-macros to Cargo.toml's dependencies:

[dependencies]
zbus-lockstep-macros = "0.5.2"

If the DBus XML descriptions can be found in the crates root, in either xml/ or XML/, validating the type can be as easy as:

 use zbus_lockstep_macros::validate;
 use zvariant::Type;

 #[validate]
 #[derive(Type)]
 struct BirthdayEvent {
    name: String,
    new_age: u8,
}

Note that the macro assumes that the member name is contained in the struct name. You can provide the member name if you have another naming-scheme in use.

Also, it may be necessary to disambiguate if multiple interfaces across the DBus descriptions provide signals with the same name.

Any of the arguments are optional.

#[validate(xml: <xml_path>, interface: <interface_name>, member: <member_name>)]

See also the crates docs for more detailed descriptions of the arguments.

LICENSE

MIT

Dependencies

~5.5MB
~113K SLoC