dbus2 / zbus-old

Rust D-Bus crate.
https://gitlab.freedesktop.org/dbus/zbus
Other
49 stars 13 forks source link

Allow interface properties to receive `#[zbus(...)]` parameters #228

Open zeenix opened 2 years ago

zeenix commented 2 years ago

In GitLab by @DataTriny on Nov 1, 2021, 11:14

Hello, To implement some interface properties, I must have access to the connection that received the call in order to build the reply. Here is an example:

#[dbus_interface(name = "org.a11y.atspi.Accessible")]
impl<T> AccessibleInterfaceObject<T>
where T: AccessibleInterface + Send + Sync + 'static
{
    #[dbus_interface(property)]
    fn parent(
        &self,
        #[zbus(connection)] connection: Connection
    ) -> ObjectAddress {
        let bus_name = connection.unique_name.unwrap();
        if let Some(parent) = self.0.parent() {
            ObjectAddress::accessible(bus_name, parent)
        } else {
            ObjectAddress::null(bus_name)
        }
    }
}

This is currently not allowed, and results in an error message:

error: custom attribute panicked
  --> platforms/linux/src/atspi/interfaces/accessible.rs:30:1
   |
30 | #[dbus_interface(name = "org.a11y.atspi.Accessible")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: message: assertion failed: name.starts_with(\"set_\")

As stated in the macro documentation, property getters must not take any argument, and setters must only take the new value. It would be nice however, if arguments marked with #[zbus(...)] were allowed.

zeenix commented 2 years ago

Thanks for filing this. This is certainly something we should support and not at all an intentional limitation.