eburghar / serde-vecmap

deserialize a map to an array of tuple (K,V) and handle Option

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Loosely based on serde-tuple-vec-map

Deserialize maps or JSON objects in serde to a vec of tuples rather than a HashMap for when you're only ever going to iterate over the result.

Usage:

// replace this:
#[derive(Serialize, Deserialize)]
struct MyStuff {
    data: HashMap<KeyType, ValueType>,
}
use serde_vecmap:vecmap;

// with this:
#[derive(Serialize, Deserialize)]
struct MyStuff {
    #[serde(with = "vecmap")]
    data: Vec<(KeyType, ValueType)>,
}

if you need an optional map

use serde_vecmap:opt_vecmap;

#[derive(Serialize, Deserialize)]
struct MyStuff {
    #[serde(with = "opt_vecmap")]
    data: Option<Vec<(KeyType, ValueType)>>,
}

About

deserialize a map to an array of tuple (K,V) and handle Option

License:MIT License


Languages

Language:Rust 100.0%