Implementation of `serde::de::Deserialize` is not general enough

Originally asked in Stackoverflow.

I want to list all the available block devices in the system using a dbus implementation called zbus.

The UDisks2 documentation mentions a method call on org.freedesktop.UDisks2.Manager interface called GetBlockDevices which accepts IN a{sv} options, OUT ao block_objects for method parameters.

Using zbus, I write:

use std::error::Error;
use std::result::Result;
use zbus::{Connection, Proxy};

fn main() -> Result<(), Box<dyn Error>> {
    let connection = Connection::new_system()?;
    let p = Proxy::new(
    let resp: Vec<zvariant::ObjectPath> ="GetBlockDevices", &std::collections::HashMap::<String, zvariant::Value>::new())?;

As far as I understand, zvariant Values represent a DBus Variant. However I get the following error:

error: implementation of `serde::de::Deserialize` is not general enough
   --> src/
13  |       let resp: Vec<zvariant::ObjectPath> ="GetBlockDevices", &std::collections::HashMap::<String, zvariant::Value>::new())?;
    |                                               ^^^^ implementation of `serde::de::Deserialize` is not general enough
   ::: /home/adnan338/.cargo/registry/src/
531 | / pub trait Deserialize<'de>: Sized {
532 | |     /// Deserialize this value from the given Serde deserializer.
533 | |     ///
534 | |     /// See the [Implementing `Deserialize`][impl-deserialize] section of the
...   |
569 | |     }
570 | | }
    | |_- trait `serde::de::Deserialize` defined here
    = note: `std::vec::Vec<zvariant::object_path::ObjectPath<'_>>` must implement `serde::de::Deserialize<'0>`, for any lifetime `'0`...
    = note: ...but `std::vec::Vec<zvariant::object_path::ObjectPath<'_>>` actually implements `serde::de::Deserialize<'1>`, for some specific lifetime `'1`

What's causing this and how can I avoid this error?

Proxy::call requires T: DerserializeOwned (T does not borrow from the input data). However, ObjectPath does not implement DeserializeOwned as it borrows from the data it deserializes from.

You can use Proxy::call_method followed by Message::body to achieve this, and you will have to bind the message to a local variable to avoid it being dropped.

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.