Open zeenix opened 1 year ago
Hi there,
at the moment there is no way to just iterate the key/value pairs of a zvariant::Dict. If you want to do it you need to convert it to a hashmap, and to do that you need to read the signature and pick a concrete type that implements Basic, it's actually quite a lot of code to do this,
So Dict
isn't really meant to be used directly. Typically you want to:
HashMap
itself. Type
is implemented for that.Value
:
SerializeDict
and DeserializeDict
derives.HashMap
to/from Value
or OwnedValue
types.Having said that, I don't know your exact use case and I have no objections on providing the API you're requesting.
I'm having trouble finding a lot of time these days for zbus work so it'll take a while, unless you could contribute this.
In GitLab by @estokes on Oct 14, 2022, 24:44
I'm bridging dbus values to another quite similar dynamically typed network protocol (netidx), so I really need to just iterate and translate the values directly (e.g. I have a recursive fn dbus_value_to_netidx_value(v: &zvariant::Value) -> Value { ... }, all of the cases are quite straightforward except zvariant::Dict).
I would be happy to work on this.
I'm bridging dbus values to another quite similar dynamically typed network protocol (netidx), so I really need to just iterate and translate the values directly (e.g. I have a recursive fn dbus_value_to_netidx_value(v: &zvariant::Value) -> Value { ... }, all of the cases are quite straightforward except zvariant::Dict).
I see. I just wanted to make sure you're not making your life harder than it needs to be. :smile:
I would be happy to work on this.
:thumbsup: I would prefer not to expose DictEntry
in pub api btw and have a generic iterator so people can iterate over specific types.
In GitLab by @estokes on Oct 12, 2022, 22:46
Hi, at the moment there is no way to just iterate the key/value pairs of a zvariant::Dict. If you want to do it you need to convert it to a hashmap, and to do that you need to read the signature and pick a concrete type that implements Basic, it's actually quite a lot of code to do this, and what I (and probably others) really want is just to iterate the values. I see that it's stored as a Vec of DictEntries, which are just the key and value, so it would be trivial to allow this iteration.
Thanks, zbus is awesome!