ics/
parameters.rs

1//! In the RFC5545 and RFC7986 specified parameters except for IANA and
2//! non-standard parameters ("X"-prefix parameters).
3//!
4//! Parameters are key-value pairs which can specify a property in detail. Some
5//! of them also specify format definitions or defined values. Those are either
6//! defined as enums or associated constants on their respective parameter.
7//!
8//! # Example
9//! ```
10//! use ics::components::Parameter;
11//! use ics::parameters::CUType;
12//!
13//! // Using associated constants or enums should be preferred over using the
14//! // generic constructors whenever possible
15//! let individual = CUType::INDIVIDUAL;
16//!
17//! assert_eq!(CUType::new("INDIVIDUAL"), individual);
18//! assert_eq!(Parameter::new("CUTYPE", "INDIVIDUAL"), individual.into());
19//! ```
20//! For more information on parameters, please refer to the specification [RFC5545 3.2. Property Parameters](https://tools.ietf.org/html/rfc5545#section-3.2) and [RFC7986 6. Property Parameters](https://tools.ietf.org/html/rfc7986#section-6).
21use crate::components::Parameter;
22use std::borrow::Cow;
23
24parameter!(AltRep, "ALTREP");
25parameter!(CN, "CN");
26parameter!(CUType, "CUTYPE");
27parameter!(DelegatedFrom, "DELEGATED-FROM");
28parameter!(DelegatedTo, "DELEGATED-TO");
29parameter!(Dir, "DIR");
30parameter!(FmtType, "FMTTYPE");
31parameter!(FBType, "FBTYPE");
32parameter!(Language, "LANGUAGE");
33parameter!(Member, "MEMBER");
34parameter!(PartStat, "PARTSTAT");
35parameter!(RelType, "RELTYPE");
36parameter!(Role, "ROLE");
37parameter!(SentBy, "SENT-BY");
38parameter!(TzIDParam, "TZID");
39parameter!(Value, "VALUE");
40
41impl CUType<'_> {
42    /// Identifies an individual (default value).
43    pub const INDIVIDUAL: Self = Self {
44        value: Cow::Borrowed("INDIVIDUAL"),
45    };
46
47    /// Identifies the calendar user as a group of individuals.
48    pub const GROUP: Self = Self {
49        value: Cow::Borrowed("GROUP"),
50    };
51
52    /// Identifies the calendar user as a physical resource.
53    pub const RESOURCE: Self = Self {
54        value: Cow::Borrowed("RESOURCE"),
55    };
56
57    /// Identifies the calendar user as a room resource
58    pub const ROOM: Self = Self {
59        value: Cow::Borrowed("ROOM"),
60    };
61
62    /// Identifies the calendar user as an unknown calendar user type.
63    pub const UNKNOWN: Self = Self {
64        value: Cow::Borrowed("UNKNOWN"),
65    };
66}
67
68impl FBType<'_> {
69    /// The time interval is free for scheduling.
70    pub const FREE: Self = Self {
71        value: Cow::Borrowed("FREE"),
72    };
73
74    /// The time interval is busy because one or more events have been scheduled for that interval (default value).
75    pub const BUSY: Self = Self {
76        value: Cow::Borrowed("BUSY"),
77    };
78
79    /// The time interval is busy and the interval cannot be scheduled.
80    pub const BUSY_UNAVAILABLE: Self = Self {
81        value: Cow::Borrowed("BUSY-UNAVAILABLE"),
82    };
83
84    /// The time interval is busy because one or more events have been tentatively scheduled for that interval.
85    pub const BUSY_TENTATIVE: Self = Self {
86        value: Cow::Borrowed("BUSY-TENTATIVE"),
87    };
88}
89
90impl PartStat<'_> {
91    /// Participation status for an Event, To-Do or Journal that needs action (default Value).
92    pub const NEEDS_ACTION: Self = Self {
93        value: Cow::Borrowed("NEEDS-ACTION"),
94    };
95
96    /// Participation status for an accepted Event, To-Do or Journal.
97    pub const ACCEPTED: Self = Self {
98        value: Cow::Borrowed("ACCEPTED"),
99    };
100
101    /// Participation status for a declined Event, To-Do or Journal.
102    pub const DECLINED: Self = Self {
103        value: Cow::Borrowed("DECLINED"),
104    };
105
106    /// Participation status for a tentatively accepted Event or To-Do.
107    pub const TENTATIVE: Self = Self {
108        value: Cow::Borrowed("TENTATIVE"),
109    };
110
111    /// Participation status for a delegated Event or To-Do.
112    pub const DELEGATED: Self = Self {
113        value: Cow::Borrowed("DELEGATED"),
114    };
115
116    /// Participation status for a completed To-Do.
117    pub const COMPLETED: Self = Self {
118        value: Cow::Borrowed("COMPLETED"),
119    };
120
121    /// Participation status for an in-process To-Do.
122    pub const IN_PROCESS: Self = Self {
123        value: Cow::Borrowed("IN-PROCESS"),
124    };
125}
126
127impl RelType<'_> {
128    /// Specifies a parent relationship (default value).
129    pub const PARENT: Self = Self {
130        value: Cow::Borrowed("PARENT"),
131    };
132
133    /// Specifies a child relationship.
134    pub const CHILD: Self = Self {
135        value: Cow::Borrowed("CHILD"),
136    };
137
138    /// Specifies a sibling relationship.
139    const SIBLING: Self = Self {
140        value: Cow::Borrowed("SIBLING"),
141    };
142
143    /// Specifies a sibling relationship.
144    // #[deprecated(note = "use RelType::SIBLING instead")]
145    pub const SILBLING: Self = Self::SIBLING;
146}
147
148impl Role<'_> {
149    /// Indicates chair of the calendar entity.
150    pub const CHAIR: Self = Self {
151        value: Cow::Borrowed("CHAIR"),
152    };
153
154    /// Indicates a participant whose participation is required (default value).
155    pub const REQ_PARTICIPANT: Self = Self {
156        value: Cow::Borrowed("REQ-PARTICIPANT"),
157    };
158
159    /// Indicates a participant whose participation is optional.
160    pub const OPT_PARTICIPANT: Self = Self {
161        value: Cow::Borrowed("OPT-PARTICIPANT"),
162    };
163
164    /// Indicates a participant who is copied for information purposes only.
165    pub const NON_PARTICIPANT: Self = Self {
166        value: Cow::Borrowed("NON-PARTICIPANT"),
167    };
168}
169
170impl Value<'_> {
171    /// Explicitly specifies the BINARY value type format for a property value.
172    pub const BINARY: Self = Self {
173        value: Cow::Borrowed("BINARY"),
174    };
175
176    /// Explicitly specifies the BOOLEAN value type format for a property value.
177    pub const BOOLEAN: Self = Self {
178        value: Cow::Borrowed("BOOLEAN"),
179    };
180
181    /// Explicitly specifies the CAL-ADDRESS value type format for a property value.
182    pub const CAL_ADDRESS: Self = Self {
183        value: Cow::Borrowed("CAL-ADDRESS"),
184    };
185
186    /// Explicitly specifies the DATE value type format for a property value.
187    pub const DATE: Self = Self {
188        value: Cow::Borrowed("DATE"),
189    };
190
191    /// Explicitly specifies the DATE-TIME value type format for a property value.
192    pub const DATE_TIME: Self = Self {
193        value: Cow::Borrowed("DATE-TIME"),
194    };
195
196    /// Explicitly specifies the DURATION value type format for a property value.
197    pub const DURATION: Self = Self {
198        value: Cow::Borrowed("DURATION"),
199    };
200
201    /// Explicitly specifies the FLOAT value type format for a property value.
202    pub const FLOAT: Self = Self {
203        value: Cow::Borrowed("FLOAT"),
204    };
205
206    /// Explicitly specifies the INTEGER value type format for a property value.
207    pub const INTEGER: Self = Self {
208        value: Cow::Borrowed("INTEGER"),
209    };
210
211    /// Explicitly specifies the PERIOD value type format for a property value.
212    pub const PERIOD: Self = Self {
213        value: Cow::Borrowed("PERIOD"),
214    };
215
216    /// Explicitly specifies the RECUR value type format for a property value.
217    pub const RECUR: Self = Self {
218        value: Cow::Borrowed("RECUR"),
219    };
220
221    /// Explicitly specifies the TEXT value type format for a property value.
222    pub const TEXT: Self = Self {
223        value: Cow::Borrowed("TEXT"),
224    };
225
226    /// Explicitly specifies the TIME value type format for a property value.
227    pub const TIME: Self = Self {
228        value: Cow::Borrowed("TIME"),
229    };
230
231    /// Explicitly specifies the URI value type format for a property value.
232    pub const URI: Self = Self {
233        value: Cow::Borrowed("URI"),
234    };
235
236    /// Explicitly specifies the UTC-OFFSET value type format for a property value.
237    pub const UTC_OFFSET: Self = Self {
238        value: Cow::Borrowed("UTC-OFFSET"),
239    };
240}
241
242impl Default for CUType<'_> {
243    fn default() -> Self {
244        Self::INDIVIDUAL
245    }
246}
247
248impl Default for FBType<'_> {
249    fn default() -> Self {
250        Self::BUSY
251    }
252}
253
254impl Default for PartStat<'_> {
255    fn default() -> Self {
256        PartStat::NEEDS_ACTION
257    }
258}
259
260impl Default for RelType<'_> {
261    fn default() -> Self {
262        Self::PARENT
263    }
264}
265
266impl Default for Role<'_> {
267    fn default() -> Self {
268        Self::REQ_PARTICIPANT
269    }
270}
271
272/// `ENCODING` Parameter
273#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
274pub enum Encoding {
275    /// `8BIT` encoding defined in RFC2045 (Text)
276    Byte,
277    /// `BASE64` encoding Format defined in RFC4648 (Binary)
278    Base64,
279}
280
281impl<'a> From<Encoding> for Parameter<'a> {
282    fn from(builder: Encoding) -> Self {
283        Parameter {
284            key: "ENCODING".into(),
285            value: match builder {
286                Encoding::Byte => Cow::Borrowed("8BIT"),
287                Encoding::Base64 => Cow::Borrowed("BASE64"),
288            },
289        }
290    }
291}
292
293impl Default for Encoding {
294    fn default() -> Self {
295        Encoding::Byte
296    }
297}
298
299/// `RANGE` Parameter
300#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
301pub enum Range {
302    /// `THISANDFUTURE` (Default Value)
303    ThisAndFuture,
304}
305
306impl<'a> From<Range> for Parameter<'a> {
307    fn from(builder: Range) -> Self {
308        Parameter {
309            key: "RANGE".into(),
310            value: match builder {
311                Range::ThisAndFuture => Cow::Borrowed("THISANDFUTURE"),
312            },
313        }
314    }
315}
316
317impl Default for Range {
318    fn default() -> Self {
319        Range::ThisAndFuture
320    }
321}
322
323/// `RELATED` Parameter
324#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
325pub enum Related {
326    /// Trigger off of `START`
327    Start,
328    /// Trigger off of `END`
329    End,
330}
331
332impl<'a> From<Related> for Parameter<'a> {
333    fn from(builder: Related) -> Self {
334        Parameter {
335            key: "RELATED".into(),
336            value: match builder {
337                Related::Start => Cow::Borrowed("START"),
338                Related::End => Cow::Borrowed("END"),
339            },
340        }
341    }
342}
343
344impl Default for Related {
345    fn default() -> Self {
346        Related::Start
347    }
348}
349
350/// RSVP Parameter
351#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
352pub enum RSVP {
353    /// `TRUE`
354    True,
355    /// `FALSE` (Default Value)
356    False,
357}
358
359impl<'a> From<RSVP> for Parameter<'a> {
360    fn from(builder: RSVP) -> Self {
361        Parameter {
362            key: "RSVP".into(),
363            value: match builder {
364                RSVP::True => Cow::Borrowed("TRUE"),
365                RSVP::False => Cow::Borrowed("FALSE"),
366            },
367        }
368    }
369}
370
371impl Default for RSVP {
372    fn default() -> Self {
373        RSVP::False
374    }
375}
376
377#[cfg(feature = "rfc7986")]
378pub use self::rfc7986::*;
379
380#[cfg(feature = "rfc7986")]
381mod rfc7986 {
382    use crate::components::Parameter;
383    use std::borrow::Cow;
384
385    parameter!(Display, "DISPLAY");
386    parameter!(Email, "EMAIL");
387    parameter!(Feature, "FEATURE");
388    parameter!(Label, "LABEL");
389
390    impl Display<'_> {
391        /// Displays an image inline with the title of the event (default value).
392        pub const BADGE: Self = Self {
393            value: Cow::Borrowed("BADGE"),
394        };
395
396        /// Displays a full image replacement for the event itself.
397        pub const GRAPHIC: Self = Self {
398            value: Cow::Borrowed("GRAPHIC"),
399        };
400
401        /// Displays an image that is used to enhance the event.
402        pub const FULLSIZE: Self = Self {
403            value: Cow::Borrowed("FULLSIZE"),
404        };
405
406        /// Displays a smaller variant of "FULLSIZE" to be used when space for the image is constrained.
407        pub const THUMBNAIL: Self = Self {
408            value: Cow::Borrowed("THUMBNAIL"),
409        };
410    }
411
412    impl Feature<'_> {
413        /// Specifies a conference or broacast system with audio capability.
414        pub const AUDIO: Self = Self {
415            value: Cow::Borrowed("AUDIO"),
416        };
417
418        /// Specifies a conference or broacast system with chat or instant messaging.
419        pub const CHAT: Self = Self {
420            value: Cow::Borrowed("CHAT"),
421        };
422
423        /// Specifies a conference or broacast system with blog or atom feed.
424        pub const FEED: Self = Self {
425            value: Cow::Borrowed("FEED"),
426        };
427
428        /// Specifies a conference or broacast system with moderator dial-in code.
429        pub const MODERATOR: Self = Self {
430            value: Cow::Borrowed("MODERATOR"),
431        };
432
433        /// Specifies a conference or broacast system with phone conference.
434        pub const PHONE: Self = Self {
435            value: Cow::Borrowed("PHONE"),
436        };
437
438        /// Specifies a conference or broacast system with screen sharing.
439        pub const SCREEN: Self = Self {
440            value: Cow::Borrowed("SCREEN"),
441        };
442
443        /// Specifies a conference or broacast system with video capability.
444        pub const VIDEO: Self = Self {
445            value: Cow::Borrowed("VIDEO"),
446        };
447    }
448
449    impl<'a> Default for Display<'a> {
450        fn default() -> Self {
451            Self::BADGE
452        }
453    }
454}