Skip to main content

Module bus

Module bus 

Source
Available on crate feature bus only.
Expand description

An interface to work with the dbus message bus.

D-Bus connections and messages.

Functions taking object paths, bus names, interface names, or member names accept both the checked types and convertible strings through crate::CStrArgument. Rust strings, C strings, owned strings, and Cow inputs are validated before the native call. Invalid values return an InvalidInput error; callers do not need to construct checked wrappers.

use std::ffi::CString;
use systemd::bus::{BusRef, Message};

fn request(bus: &mut BusRef) -> systemd::Result<Message> {
    bus.new_method_call("org.example.Service", "/org/example/Object",
        CString::new("org.example.Interface").unwrap(), "Ping")
}

Checked constructors also accept convertible strings. Their Cow result borrows existing C strings and owns converted Rust strings. Use into_owned() for storage independent of an input borrow:

use std::borrow::Cow;
use std::ffi::CString;
use systemd::bus::{ObjectPath, ObjectPathBuf, BusName, InterfaceName, MemberName};
let input = CString::new("/org/example/Object").unwrap();
let borrowed = ObjectPath::new(input.as_c_str()).unwrap();
assert!(matches!(borrowed, Cow::Borrowed(_)));
let stored: ObjectPathBuf = borrowed.into_owned();
drop(input);
assert_eq!(stored.to_bytes(), b"/org/example/Object");
let _ = ObjectPath::new("/org/example/Other").unwrap();
let _ = BusName::new("org.example.Service").unwrap();
let _ = InterfaceName::new("org.example.Interface").unwrap();
let _ = MemberName::new("Ping").unwrap();
assert!(ObjectPath::new("invalid path").is_err());

A borrowed checked value cannot outlive its input:

ⓘ
use std::{borrow::Cow, ffi::CString};
use systemd::bus::ObjectPath;
fn escape() -> Cow<'static, ObjectPath> {
    let input = CString::new("/org/example/Object").unwrap();
    ObjectPath::new(input.as_c_str()).unwrap()
}

Modules§

types
Typed D-Bus containers: vectors are arrays, tuples are structs, and maps are dictionaries. Variant<T> wraps one value with its wire signature. Struct tuples have one to twelve fields. Empty arrays and dictionaries keep their element types. Map decoding rejects duplicate keys; use a vector of DictEntry values when duplicates or wire order need to be preserved.

Structs§

Bus
BusName
BusNameBuf
Owned, validated storage for BusName.
BusRef
A borrowed reference to a Bus.
Error
InterfaceName
A wrapper which promises it always holds a validated dbus interface name
InterfaceNameBuf
Owned, validated storage for InterfaceName.
MemberName
MemberNameBuf
Owned, validated storage for MemberName.
Message
A message to be sent or that was received over dbus
MessageIter
An iterator over the elements of a Message, use this to read data out of a message.
MessageRef
A borrowed reference to a Message.
ObjectPath
A wrapper which promises it always holds a valid dbus object path
ObjectPathBuf
Owned, validated storage for ObjectPath.
RawError
Vtable
An owned interface definition for BusRef::add_object_vtable.
VtableFlags
Flags for vtable entries. Combine flags with |. The default is no flags, matching libsystemd. Flags that change userdata offsets are not exposed.

Enums§

ContainerType
Container kinds accepted by libsystemd’s open/enter container APIs. Structs and dictionary entries use r and e here; their signatures use parentheses and braces respectively.
MessageType

Type Aliases§

Result
Result type for dbus calls that contains errors returned by remote services (and local errors as well).