mapping.rs 513 Bytes
Newer Older
Cyril Plisko's avatar
Cyril Plisko committed
1 2
use std::collections::HashMap;

3 4
use serde::Serialize;

Cyril Plisko's avatar
Cyril Plisko committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#[derive(Clone, Debug, Default, Serialize)]
pub struct Mapping(HashMap<String, HashMap<String, String>>);

impl Mapping {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn add(
        &mut self,
        key: impl Into<String>,
        map: impl IntoIterator<Item = (String, String)>,
    ) -> &mut Self {
        let key = key.into();
        let value = map.into_iter().collect();
        self.0.insert(key, value);
        self
    }
}