Dbus: implementation of `Get` is not general enough

I'm trying to get 'Interfaces' property use dbus-rs crate, but it always complains "implementation of Get is not general enough", here is the code:

use dbus::arg::Array;
use dbus::blocking::stdintf::org_freedesktop_dbus::Properties;
use dbus::blocking::Connection;
use std::time::Duration;

fn main() {
    let dbus = Connection::new_system().unwrap();

    let proxy = dbus.with_proxy(
        "fi.w1.wpa_supplicant1",
        "/fi/w1/wpa_supplicant1",
        Duration::from_secs(1),
    );

    let interfaces: Result<Array<u16, _>, _> =
        proxy.get("fi.w1.wpa_supplicant1", "Interfaces");

    println!("{:?}", interfaces);
}

and the compile error messages:

    Checking dbus_learn v0.1.0
error: implementation of `Get` is not general enough
  --> src/main.rs:16:9
   |
16 |         proxy.get("fi.w1.wpa_supplicant1", "Interfaces");
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Get` is not general enough
   |
   = note: `Get<'0>` would have to be implemented for the type `dbus::arg::Array<'_, u16, dbus::arg::Iter<'_>>`, for any lifetime `'0`...
   = note: ...but `Get<'1>` is actually implemented for the type `dbus::arg::Array<'1, u16, dbus::arg::Iter<'1>>`, for some specific lifetime `'1`

error: could not compile `dbus_learn` (bin "dbus_learn") due to 1 previous error

I don't understand what's the difference of "Get<'0>" with "Get<'1>", the two seems have the same type.

The important part is at the end of the line:

... for any lifetime `'0`...
for some specific lifetime `'1`

In practice the problem is that Array holds a lifetime and likely borrows from something and is constructible through the Get trait only by passing a reference of the same lifetime as Array (this is what "for some specific lifetime '1" means), but the bound of the get method requires it to be constructible with a reference of any lifetime.

Moreover, the get method requires the type to also be 'static, so there's no way Array would work here. You want something that completly owns its items, like a Vec.

2 Likes

Thanks! you're right, it works after changed to Vec<dbus::strings::Path>

let interfaces: Result<Vec<Path>, _> =
        proxy.get("fi.w1.wpa_supplicant1", "Interfaces");

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.