The first thing you will have to do is to connect to a D-Bus bus or to a D-Bus peer. This is the entry point of the zbus API.
To connect to the session bus (the per-user bus), simply call
returns an instance of the connection (if all went well).
Note: it is common for a D-Bus library to provide a “shared” connection to a bus for a process:
new_session() share the same underlying connection for example. At the time of this writing,
zbus doesn’t do that.
You may also specify a custom bus with
Connection::new_for_address() which takes a D-Bus address
as specified in the
Peer-to-peer connections are bus-less1, and the initial handshake protocol is a bit different. There is the notion of client & server endpoints, but that distinction doesn’t matter once the connection is established (both ends are equal, and can send any messages).
To create a bus-less peer-to-peer connection on Unix, you can make a
socketpair() (or have a
listening socket server, accepting multiple connections), and hand over the socket FDs to
Connection::new_unix_client for each side. After success, you
can call the
Connection methods to send and receive messages on both ends.
unix_p2p test in the zbus source code for a simple example.
1 Unless you implemented them, none of the bus methods will exist.