icalendar/components/
other.rs

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
46
47
48
49
50
51
52
53
54
55
56
57
use super::*;

#[derive(Debug, Default, PartialEq, Eq, Clone)]
pub struct Other {
    name: String,
    pub(super) inner: InnerComponent,
}

impl Component for Other {
    /// Tells you what kind of `Component` this is
    ///
    /// Might be `VEVENT`, `VTODO`, `VALARM` etc
    fn component_kind(&self) -> String {
        self.name.clone()
    }

    /// Read-only access to `properties`
    fn properties(&self) -> &BTreeMap<String, Property> {
        &self.inner.properties
    }

    /// Read-only access to child `components`
    fn components(&self) -> &[Other] {
        &self.inner.components
    }

    /// Read-only access to `multi_properties`
    fn multi_properties(&self) -> &BTreeMap<String, Vec<Property>> {
        &self.inner.multi_properties
    }

    /// Adds a `Property`
    fn append_property(&mut self, property: impl Into<Property>) -> &mut Self {
        let property = property.into();
        self.inner
            .properties
            .insert(property.key().to_owned(), property);
        self
    }

    /// Adds a `Property` of which there may be many
    fn append_multi_property(&mut self, property: impl Into<Property>) -> &mut Self {
        self.inner.insert_multi(property);
        self
    }

    fn append_component(&mut self, child: impl Into<Other>) -> &mut Self {
        self.inner.components.push(child.into());
        self
    }
}

impl From<(String, InnerComponent)> for Other {
    fn from((name, inner): (String, InnerComponent)) -> Self {
        Self { name, inner }
    }
}