diff --git a/src/components.rs b/src/components.rs index c83a260..7167804 100644 --- a/src/components.rs +++ b/src/components.rs @@ -145,13 +145,14 @@ pub trait Component { fn append_multi_property(&mut self, property: impl Into) -> &mut Self; /// Construct and append a [`Property`] - fn add_property(&mut self, key: &str, val: &str) -> &mut Self { + fn add_property(&mut self, key: impl Into, val: impl Into) -> &mut Self { self.append_property(Property::new(key, val)) } + #[deprecated] /// Construct and append a [`Property`] fn add_property_pre_alloc(&mut self, key: String, val: String) -> &mut Self { - self.append_property(Property::new_pre_alloc(key, val)) + self.append_property(Property::new(key, val)) } /// Construct and append a [`Property`] @@ -254,7 +255,7 @@ pub trait Component { /// Set the sequence fn sequence(&mut self, sequence: u32) -> &mut Self { - self.add_property_pre_alloc("SEQUENCE".into(), sequence.to_string()) + self.add_property("SEQUENCE", sequence.to_string()) } /// Gets the SEQUENCE diff --git a/src/components/alarm.rs b/src/components/alarm.rs index 2f72a85..3b45d89 100644 --- a/src/components/alarm.rs +++ b/src/components/alarm.rs @@ -351,7 +351,7 @@ pub mod properties { impl From for Property { fn from(r: Repeat) -> Self { - Property::new_pre_alloc("REPEAT".into(), r.0.to_string()) + Property::new("REPEAT", r.0.to_string()) } } @@ -544,14 +544,12 @@ pub mod properties { fn from(trigger: Trigger) -> Self { match trigger { Trigger::Duration(duration, Some(related)) => { - Property::new_pre_alloc("TRIGGER".into(), duration.to_string()) + Property::new("TRIGGER", duration.to_string()) .append_parameter(related) .done() } - Trigger::Duration(duration, None) => { - Property::new_pre_alloc("TRIGGER".into(), duration.to_string()) - } + Trigger::Duration(duration, None) => Property::new("TRIGGER", duration.to_string()), Trigger::DateTime(dt) => dt .to_property("TRIGGER") diff --git a/src/properties.rs b/src/properties.rs index b710b91..1721509 100644 --- a/src/properties.rs +++ b/src/properties.rs @@ -53,14 +53,15 @@ impl From<(&str, &str)> for Property { impl Property { /// Guess what this does :D - pub fn new(key: &str, val: &str) -> Self { + pub fn new(key: impl Into, val: impl Into) -> Self { Property { - key: key.to_owned(), - val: val.to_owned(), + key: key.into(), + val: val.into(), params: HashMap::new(), } } + #[deprecated] /// if you already have `String`s I'll gladly take pub fn new_pre_alloc(key: String, val: String) -> Self { Property { @@ -333,22 +334,22 @@ impl From for Parameter { impl From for Property { fn from(val: TodoStatus) -> Self { - Property::new_pre_alloc( - String::from("STATUS"), - String::from(match val { + Property::new( + "STATUS", + match val { TodoStatus::NeedsAction => "NEEDS-ACTION", TodoStatus::Completed => "COMPLETED", TodoStatus::InProcess => "IN-PROCESS", TodoStatus::Cancelled => "CANCELLED", //TodoStatus::Custom(s) => "CU", - }), + }, ) } } impl From for Property { fn from(duration: chrono::Duration) -> Self { - Property::new_pre_alloc(String::from("DURATION"), duration.to_string()) + Property::new("DURATION", duration.to_string()) } } //pub enum AttendeeRole {