dbus2 / zbus-old

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

dbus_interface macro fails to cast from Dictionary to Value #287

Closed zeenix closed 1 year ago

zeenix commented 1 year ago

In GitLab by @ivakam on Sep 22, 2022, 24:13

I've implemented a Dictionary struct as per the FAQ as follows:

#[derive(DeserializeDict, SerializeDict, Type, Value, OwnedValue, Clone)]
#[zvariant(signature = "dict")]
pub struct Dictionary {
    #[zvariant(rename = "xesam:title")]
    pub(crate) f1: String,
    #[zvariant(rename = "xesam:artist")]
    pub(crate) f2: Vec<String>,
    #[zvariant(rename = "xesam:album")]
    pub(crate) f3: String,
}

This struct is used in my interface struct that uses the dbus_interface macro with the following getter/setter methods:

    #[dbus_interface(property)]
    async fn metadata(&self) -> Dictionary {
        self.metadata.clone()
    }

    #[dbus_interface(property)]
    async fn set_metadata(&mut self, metadata: Dictionary) {
        self.metadata = metadata;
    }

This fails to compile with the following error: image

If I remove the metadata field (and methods) from the interface, it compiles without any issues.

This does not feel like intended behavior since the Dictionary struct explicitly derives Value and OwnedValue to allow casting to and from, which is precisely what the compile error is about.

zeenix commented 1 year ago

Thanks so much for reporting this with all the details. Turns out it's been a forgotten issue already known. But it's great you reported cause now I've easy access to reproducer. But let's track it on #248.

zeenix commented 1 year ago

marked this issue as a duplicate of #248

zeenix commented 1 year ago

marked this issue as related to #248