dbus2 / zbus

Rust D-Bus crate.
Other
383 stars 87 forks source link

Shared interface between interface and proxy #236

Closed zeenix closed 4 months 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

zeenix commented 1 year ago

Since #225 turned out to be not so easy (especially if we do it in such a way that it paves the way to solve this), I think the best way forward is to achieve this though dbus_interface gaining the ability to generate the dbus_proxy for you. That way you've far less typing involved and this can be done w/o breaking API though introduction of new macro attribute(s).

I believe this would be the best way forward here.