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
use std::collections::BTreeMap;
use std::ops::{Deref, DerefMut};

/// Contains all properties for telemetry to submit.
#[derive(Clone, Default)]
pub struct Properties(BTreeMap<String, String>);

impl Properties {
    /// Combines all properties from two objects. It can override some properties with values found
    /// in the second properties bag.
    pub fn combine(a: Properties, b: Properties) -> Self {
        let items = a.0.into_iter().chain(b.0).collect();
        Self(items)
    }
}

impl From<Properties> for BTreeMap<String, String> {
    fn from(properties: Properties) -> Self {
        properties.0
    }
}

impl Deref for Properties {
    type Target = BTreeMap<String, String>;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

impl DerefMut for Properties {
    fn deref_mut(&mut self) -> &mut Self::Target {
        &mut self.0
    }
}