dbus2 / zbus

Rust D-Bus crate.
Other
329 stars 74 forks source link

proxy macro panics when one of the methods is `fn r#type(&self)` #214

Open zeenix opened 2 years ago

zeenix commented 2 years ago

In GitLab by @MaxVerevkin on Oct 13, 2021, 17:43

#[dbus_proxy(
    interface = "org.freedesktop.UPower.Device",
    default_service = "org.freedesktop.UPower"
)]
trait Device {
    /// Type property
    #[dbus_proxy(property)]
    fn r#type(&self) -> zbus::Result<u32>;
}

Fails:

error: custom attribute panicked
  --> src/blocks/battery/zbus_upower.rs:24:1
   |
24 | / #[dbus_proxy(
25 | |     interface = "org.freedesktop.UPower.Device",
26 | |     default_service = "org.freedesktop.UPower"
27 | | )]
   | |__^
   |
   = help: message: `"cached_r#type"` is not a valid identifier
zeenix commented 2 years ago

Is this with 1.x or latest 2.0 beta?

Any easy work around is to make use of name attribute to avoid keywords:

    #[dbus_proxy(property, name = "Type")]
    fn type_(&self) -> zbus::Result<u32>;

See also https://gitlab.freedesktop.org/dbus/zbus/-/issues/133.

zeenix commented 2 years ago

In GitLab by @MaxVerevkin on Oct 14, 2021, 15:23

@zeenix Thanks for the workaround! This affects current master branch as well as latest beta.