1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::collections::BTreeMap;

#[derive(Clone, Debug, Default)]
pub struct Meta {
    key: &'static str,
    value: &'static str,
}

impl Meta {
    pub fn new(key: &'static str, value: &'static str) -> Self {
        Self { key, value }
    }

    pub fn key(&self) -> &'static str {
        self.key
    }

    pub fn value(&self) -> &'static str {
        self.value
    }
}

#[derive(Clone, Debug, Default)]
pub struct Metas {
    metas: BTreeMap<&'static str, &'static str>,
}

impl Metas {
    pub fn add(&mut self, key: &'static str, value: &'static str) {
        self.metas.insert(key, value);
    }

    pub fn with(mut self, key: &'static str, value: &'static str) -> Self {
        self.add(key, value);
        self
    }

    pub fn iter(&self) -> impl Iterator<Item = Meta> + '_ {
        self.metas.iter().map(|(&k, &v)| Meta::new(k, v))
    }

    pub fn get(&self, key: &'static str) -> Option<&'static str> {
        self.metas.get(key).cloned()
    }
}