Derive Macro zvariant::DeserializeDict[][src]

    // Attributes available to this derive:
Expand description

Adds Deserialize implementation to structs to be deserialized from a{sv} type.

This macro deserializes a D-Bus dictionary type as a struct, where keys are strings and values are generic values. Such dictionary types are very commonly used with D-Bus and GVariant.


For structs it works just like serde’s Deserialize macros:

use zvariant::{EncodingContext, to_bytes, DeserializeDict, TypeDict};

#[derive(DeserializeDict, TypeDict)]
struct Struct {
    field1: u16,
    #[zvariant(rename = "another-name")]
    field2: i64,
    optional_field: Option<String>,

The deserialized D-Bus dictionary {"field1": Value::U16(42), "another-name": Value::I64(77)} will be Struct {42, 77, None}.