zbus-old icon indicating copy to clipboard operation
zbus-old copied to clipboard

Shared interface between dbus_interface and dbus_proxy

Open zeenix opened this issue 3 years ago • 3 comments
trafficstars

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 avatar Jan 05 '22 18:01 zeenix

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 avatar Jan 12 '22 00:01 zeenix

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

zeenix avatar Jan 12 '22 00:01 zeenix

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

zeenix avatar Jan 12 '22 00:01 zeenix