summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHendrik Sollich <hoodie@users.noreply.github.com>2018-12-21 02:11:34 +0100
committerGitHub <noreply@github.com>2018-12-21 02:11:34 +0100
commitcf0ffcf0b0930bd54a37ebc6995938dc95b5c9fa (patch)
treec2be42663d1affac80b3cb90519b667aaed4fc31
parentb4594d29bff013913c1133a3b36ee363bfd1e46c (diff)
parent01ae766aa833fe0bd09885438f4bfe22c113359e (diff)
Merge pull request #4 from fernandobatels/master
Uid property
-rw-r--r--examples/write.rs1
-rw-r--r--src/components.rs11
2 files changed, 11 insertions, 1 deletions
diff --git a/examples/write.rs b/examples/write.rs
index 82e0d20..a6488ad 100644
--- a/examples/write.rs
+++ b/examples/write.rs
@@ -17,6 +17,7 @@ fn main() {
.add_parameter("IMPORTANCE", "very")
.add_parameter("DUE", "tomorrow")
.done())
+ .uid("my.own.id")
.done();
let bday = Event::new()
diff --git a/src/components.rs b/src/components.rs
index a37a9b9..34e29d5 100644
--- a/src/components.rs
+++ b/src/components.rs
@@ -129,12 +129,15 @@ pub trait Component {
write_crlf!(out, "BEGIN:{}", Self::component_kind())?;
let now = Local::now().format("%Y%m%dT%H%M%S");
write_crlf!(out, "DTSTAMP:{}", now)?;
- write_crlf!(out, "UID:{}", Uuid::new_v4())?;
for property in self.properties().values() {
property.fmt_write(out)?;
}
+ if !self.properties().keys().any(|key| key == "UID") {
+ write_crlf!(out, "UID:{}", Uuid::new_v4())?;
+ }
+
for property in self.multi_properties() {
property.fmt_write(out)?;
}
@@ -262,6 +265,12 @@ pub trait Component {
self
}
+ /// Set the UID
+ fn uid(&mut self, uid: &str) -> &mut Self {
+ self.add_property("UID", uid);
+ self
+ }
+
/// Set the visibility class
fn class(&mut self, class: Class) -> &mut Self {
self.append_property(class.into())