ics/properties.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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
//! In the RFC5545 and RFC7986 specified properties except for IANA and
//! non-standard properties ("X"-prefix parameters).
//!
//! Properties are key-value pairs which can have optionally several
//! parameters. A property forms a content line which is line folded (CRLF +
//! whitespace) after 75 bytes automatically for you.
//!
//! Additionally, some of them also specify format definitions or defined
//! values. Those are associated functions or constructors.
//!
//! # Example
//! ```
//! use ics::components::Property;
//! use ics::properties::Class;
//!
//! // Using associated functions should be preferred over using the generic
//! // constructors whenever possible
//! let confidential = Class::confidential();
//!
//! assert_eq!(Class::new("CONFIDENTIAL"), confidential);
//! assert_eq!(Property::new("CLASS", "CONFIDENTIAL"), confidential.into());
//! ```
//! For more information on properties, please refer to the specification [RFC5545 3.7. Calendar Properties](https://tools.ietf.org/html/rfc5545#section-3.7) and [RFC7986 5. Properties](https://tools.ietf.org/html/rfc7986#section-5).
use crate::components::{Parameter, Parameters, Property};
use std::borrow::Cow;
use std::collections::BTreeMap;
property!(CalScale, "CALSCALE");
property!(Method, "METHOD");
property!(ProdID, "PRODID");
property!(Version, "VERSION");
property!(Attach, "ATTACH");
property!(Categories, "CATEGORIES");
property!(Class, "CLASS");
property!(Comment, "COMMENT");
property!(Description, "DESCRIPTION");
property!(Geo, "GEO");
property!(Location, "LOCATION");
property!(PercentComplete, "PERCENT-COMPLETE");
property!(Priority, "PRIORITY");
property!(Resources, "RESOURCES");
property!(Status, "STATUS");
property!(Summary, "SUMMARY");
property!(Completed, "COMPLETED");
property!(DtEnd, "DTEND");
property!(Due, "DUE");
property!(DtStart, "DTSTART");
property!(Duration, "DURATION");
property!(FreeBusyTime, "FREEBUSY");
property!(Transp, "TRANSP");
property!(TzID, "TZID");
property!(TzName, "TZNAME");
property!(TzOffsetFrom, "TZOFFSETFROM");
property!(TzOffsetTo, "TZOFFSETTO");
property!(TzURL, "TZURL");
property!(Attendee, "ATTENDEE");
property!(Contact, "CONTACT");
property!(Organizer, "ORGANIZER");
property!(RecurrenceID, "RECURRENCE-ID");
property!(RelatedTo, "RELATED-TO");
property!(URL, "URL");
property!(UID, "UID");
property!(ExDate, "EXDATE");
property!(RDate, "RDATE");
property!(RRule, "RRULE");
property!(Action, "ACTION");
property!(Repeat, "REPEAT");
property!(Trigger, "TRIGGER");
property!(Created, "CREATED");
property!(DtStamp, "DTSTAMP");
property!(LastModified, "LAST-MODIFIED");
property!(Sequence, "SEQUENCE");
property!(RequestStatus, "REQUEST-STATUS");
impl Class<'_> {
/// Specifies the access classification as public for a component (default value).
pub fn public() -> Self {
Self::new("PUBLIC")
}
/// Specifies the access classification as private for a component.
pub fn private() -> Self {
Self::new("PRIVATE")
}
/// Specifies the access classification as confidential for a component.
pub fn confidential() -> Self {
Self::new("CONFIDENTIAL")
}
}
impl Status<'_> {
/// Status for a tentative event.
pub fn tentative() -> Self {
Self::new("TENTATIVE")
}
/// Status for a definite event.
pub fn confirmed() -> Self {
Self::new("CONFIRMED")
}
/// Status for a cancelled Event, To-Do or Journal.
pub fn cancelled() -> Self {
Self::new("CANCELLED")
}
/// Status for a To-Do that needs action.
pub fn needs_action() -> Self {
Self::new("NEEDS-ACTION")
}
/// Status for a completed To-Do.
pub fn completed() -> Self {
Self::new("COMPLETED")
}
/// Status for an in-process To-Do.
pub fn in_process() -> Self {
Self::new("IN-PROCESS")
}
/// Status for a draft Journal.
pub fn draft() -> Self {
Self::new("DRAFT")
}
/// Status for a final Journal.
pub fn final_() -> Self {
Self::new("FINAL")
}
}
impl Transp<'_> {
/// Blocks or opaque on busy time searches (default value).
pub fn opaque() -> Self {
Self::new("OPAQUE")
}
/// Transparent on busy time searches.
pub fn transparent() -> Self {
Self::new("TRANSPARENT")
}
}
impl Action<'_> {
/// Specifies an audio action to be invoked when an alarm is triggered.
pub fn audio() -> Self {
Self::new("AUDIO")
}
/// Specifies a display action to be invoked when an alarm is triggered.
pub fn display() -> Self {
Self::new("DISPLAY")
}
/// Specifies an email action to be invoked when an alarm is triggered.
pub fn email() -> Self {
Self::new("EMAIL")
}
}
impl Default for Class<'_> {
fn default() -> Self {
Self::public()
}
}
impl Default for Transp<'_> {
fn default() -> Self {
Self::opaque()
}
}
impl Default for CalScale<'_> {
fn default() -> Self {
Self {
value: Cow::Borrowed("GREGORIAN"),
parameters: BTreeMap::new(),
}
}
}
impl Default for Priority<'_> {
fn default() -> Self {
Self {
value: Cow::Borrowed("0"),
parameters: BTreeMap::new(),
}
}
}
impl Default for Repeat<'_> {
fn default() -> Self {
Self {
value: Cow::Borrowed("0"),
parameters: BTreeMap::new(),
}
}
}
impl Default for Sequence<'_> {
fn default() -> Self {
Self {
value: Cow::Borrowed("0"),
parameters: BTreeMap::new(),
}
}
}
#[cfg(feature = "rfc7986")]
pub use self::rfc7986::*;
#[cfg(feature = "rfc7986")]
mod rfc7986 {
use crate::components::{Parameter, Parameters, Property};
use std::borrow::Cow;
use std::collections::BTreeMap;
property!(Name, "NAME");
property_with_parameter!(RefreshInterval, "REFRESH-INTERVAL", "DURATION");
property_with_parameter!(Source, "SOURCE", "URI");
property!(Color, "COLOR");
property_with_parameter!(Conference, "CONFERENCE", "URI");
/// `IMAGE` Property
///
/// Newer properties that have a different value type than `TEXT` have to
/// include the `VALUE` parameter. This property already contains the
/// `VALUE` parameter, do not add this parameter manually. Depending on
/// the constructor the value can be either `URI` or `BINARY`.
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Image<'a> {
value: Cow<'a, str>,
parameters: Parameters<'a>,
}
impl<'a> Image<'a> {
/// Creates a new `IMAGE` Property with the given value. The value type
/// is `URI`.
pub fn uri<S>(value: S) -> Self
where
S: Into<Cow<'a, str>>,
{
Image {
value: value.into(),
parameters: parameters!("VALUE" => "URI"),
}
}
/// Creates a new `IMAGE` Property with the given value.
/// The value type is `BINARY` which is why the `ENCODING` parameter
/// with the value `BASE64` is also added.
pub fn binary<S>(value: S) -> Self
where
S: Into<Cow<'a, str>>,
{
Image {
value: value.into(),
parameters: parameters!("ENCODING" => "BASE64"; "VALUE" => "BINARY"),
}
}
}
impl_add_parameters!(Image);
impl_from_prop!(Image, "IMAGE");
}