dbus2 / zbus-old

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

dbus_interface property setters fails with custom type #257

Closed zeenix closed 1 year ago

zeenix commented 2 years ago

In GitLab by @bilelmoussaoui on Jan 31, 2022, 14:31

If you are writing a dbus interface, and you have a custom wrapper type like

#[derive(Serialize, Deserialize, Type, Value)]
pub struct MyCustomType(String);

Passing that type to your interface to set a property makes it fail

#[derive(Debug)]
pub struct MyInterface {}

#[dbus_interface(name = "org.freedesktop.MySuperInterface")]
impl MyInterface {
    #[dbus_interface(property)]
    fn my_custom_type(&self) -> MyCustomType {
        todo!()
    }

    #[dbus_interface(property)]
    fn set_my_custom_type(&mut self, my_custom_type: MyCustomType) {
    }
}

The error would be something like

error[E0308]: mismatched types
  --> src/service/client.rs:17:1
   |
17 | #[dbus_interface(name = "org.freedesktop.GeoClue2.Client")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `zbus::zvariant::Error`, found enum `Infallible`
   |
note: return type inferred to be `zbus::zvariant::Error` here
  --> src/service/client.rs:17:1
   |
17 | #[dbus_interface(name = "org.freedesktop.GeoClue2.Client")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = note: this error originates in the attribute macro `dbus_interface` (in Nightly builds, run with -Z macro-backtrace for more info)

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.

I tend to believe it is caused by this https://gitlab.freedesktop.org/dbus/zbus/-/blob/main/zbus_macros/src/iface.rs#L236 but who knows

zeenix commented 2 years ago

mentioned in commit 96b6188af1e3a1ad2cc5e3ebec88de8e4b5b3722