evobench_tools/serde_types/
map.rs

1//! A map that supports serde and construction via `Vec<KeyVal>`, and
2//! that way, command line parsing via clap.
3
4use std::collections::BTreeMap;
5
6use super::key_val::KeyVal;
7
8#[derive(Debug, PartialEq, Clone, serde::Serialize, serde::Deserialize)]
9pub struct Map<K: Ord, V>(BTreeMap<K, V>);
10
11/// Relying on `KeyVal`, i.e. parsing a sequence of "FOO=bar" style
12/// strings
13impl<KV: AsRef<KeyVal>, T: IntoIterator<Item = KV>> From<T> for Map<String, String> {
14    fn from(keyvals: T) -> Self {
15        let mut m = BTreeMap::new();
16        for kv in keyvals {
17            let KeyVal { key, val } = kv.as_ref();
18            m.insert(key.to_owned(), val.to_owned());
19        }
20        Self(m)
21    }
22}