dbus2 / zbus-old

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

Shared interface between dbus_interface and dbus_proxy #246

Open zeenix opened 2 years ago

zeenix commented 2 years ago

A lot of times, codebases have both the service and client side so it'd be ideal with the API declaration (i-e the trait declaration given to the dbus_proxy macro) could be shared between dbus_proxy and dbus_interface. Something like:

#[dbus_interface(interface = "org.blah")]
#[dbus_proxy(interface = "org.blah")]
// Might be better to even provide another macro that combines the above two?
trait Blah {
    fn blah(&self, arg: &str) -> Result<usize>;
}

// xmlgen can generate the above part.

struct BlahImpl;

impl Blah for BlahImpl {
   fn blah(&self, arg: &str) -> Result<usize> {
       Ok(arg.len())
   }
}

Related: #118, #225.

zeenix commented 2 years ago

In GitLab by @ids1024 on Jan 12, 2022, 01:21

How would such a trait fit with async use cases? That would require different function signatures for methods, and async trait methods are still not supported by Rust.

zeenix commented 2 years ago

We already support async traits through the async-trait crate. Both proxy and interface methods are async in 2.0 essentially.

zeenix commented 2 years ago

https://gitlab.freedesktop.org/dbus/zbus/-/blob/main/zbus/src/interface.rs#L48