DeserializeQuery

Derive Macro DeserializeQuery 

Source
#[derive(DeserializeQuery)]
{
    // Attributes available to this derive:
    #[query]
}
Expand description

Derive macro for DeserializeQuery trait.

Please refer to the module-level documentation for the usage.

ยงExample

use serde_query::{DeserializeQuery, Query};

#[derive(DeserializeQuery)]
struct Data {
    #[query(".commits.[].author")]
    authors: Vec<String>,
    #[query(".count")]
    count: usize,
}

let document = serde_json::json!({
    "commits": [
        {
            "author": "Kou",
            "hash": 0x0202,
        },
        {
            "author": "Kasumi",
            "hash": 0x1013,
        },
        {
            "author": "Masaru",
            "hash": 0x0809,
        },
    ],
    "count": 3,
}).to_string();

// You can use `Query<T>` as a `Deserialize` type for any `Deserializer`
// and convert the result to the desired type using `From`/`Into`.
let data: Data = serde_json::from_str::<Query<Data>>(&document)?.into();

assert_eq!(data.authors, vec!["Kou", "Kasumi", "Masaru"]);
assert_eq!(data.count, 3);