Skip to main content

icalendar/components/
event.rs

1use super::*;
2/// VEVENT [(RFC 5545, Section 3.6.1 )](https://tools.ietf.org/html/rfc5545#section-3.6.1)
3#[derive(Debug, Default, PartialEq, Eq, Clone)]
4pub struct Event {
5    pub(super) inner: InnerComponent,
6}
7
8impl Event {
9    /// Creates a new Event.
10    pub fn new() -> Self {
11        Default::default()
12    }
13
14    /// Creates a new Event with a UID.
15    pub fn with_uid(uid: &str) -> Self {
16        Self::new().uid(uid).done()
17    }
18
19    /// End of builder pattern.
20    /// copies over everything
21    pub fn done(&mut self) -> Self {
22        Event {
23            inner: self.inner.done(),
24        }
25    }
26
27    /// Defines the overall status or confirmation
28    pub fn status(&mut self, status: EventStatus) -> &mut Self {
29        self.append_property(status)
30    }
31
32    /// Gets the overall status or confirmation.
33    pub fn get_status(&self) -> Option<EventStatus> {
34        EventStatus::from_str(self.property_value("STATUS")?)
35    }
36
37    //pub fn repeats<R:Repeater+?Sized>(&mut self, repeat: R) -> &mut Self {
38    //    unimplemented!()
39    //}
40
41    /// Remove the status property from an event
42    pub fn remove_status(&mut self) -> &mut Self {
43        self.remove_property("STATUS")
44    }
45}
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn get_properties_unset() {
53        let event = Event::new();
54        assert_eq!(event.get_status(), None);
55    }
56
57    #[test]
58    fn get_properties_set() {
59        let event = Event::new().status(EventStatus::Tentative).done();
60        assert_eq!(event.get_status(), Some(EventStatus::Tentative));
61    }
62
63    #[test]
64    fn test_remove_status() {
65        let mut event = Event::new().status(EventStatus::Cancelled).done();
66
67        assert_eq!(event.get_status(), Some(EventStatus::Cancelled));
68
69        event.remove_status();
70
71        assert_eq!(event.get_status(), None);
72    }
73}