Skip to content

Commit

Permalink
refactor:deprecate pre_alloc version by making the default new generic
Browse files Browse the repository at this point in the history
  • Loading branch information
marcantoinem committed Aug 25, 2024
1 parent e036d63 commit 7b0669b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,14 @@ pub trait Component {
fn append_multi_property(&mut self, property: impl Into<Property>) -> &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<String>, val: impl Into<String>) -> &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`]
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions src/components/alarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ pub mod properties {

impl From<Repeat> for Property {
fn from(r: Repeat) -> Self {
Property::new_pre_alloc("REPEAT".into(), r.0.to_string())
Property::new("REPEAT", r.0.to_string())
}
}

Expand Down Expand Up @@ -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")
Expand Down
17 changes: 9 additions & 8 deletions src/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, val: impl Into<String>) -> 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 {
Expand Down Expand Up @@ -333,22 +334,22 @@ impl From<ValueType> for Parameter {

impl From<TodoStatus> 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<chrono::Duration> 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 {
Expand Down

0 comments on commit 7b0669b

Please sign in to comment.