summaryrefslogtreecommitdiffstats
path: root/src/khline.rs
diff options
context:
space:
mode:
authorVincent Breitmoser <look@my.amazin.horse>2019-01-12 17:26:59 +0100
committerVincent Breitmoser <look@my.amazin.horse>2019-01-12 17:26:59 +0100
commitb71bdfdc9156617d6d2d4ae4d6c5cc0ce7f311e4 (patch)
tree3c338307cb49b8c55b3c1fe7925e279189a8b924 /src/khline.rs
parentbef793dbba795033bc7ce256d085ef52a9c0cab0 (diff)
khline: improve trait structure
Diffstat (limited to 'src/khline.rs')
-rw-r--r--src/khline.rs28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/khline.rs b/src/khline.rs
index ab2f063..ccde951 100644
--- a/src/khline.rs
+++ b/src/khline.rs
@@ -24,17 +24,6 @@ impl KhLine {
Self { path, time }
}
- pub fn from(event: &IcalVEvent) -> Option<KhLine> {
- let path = event.get_parent()?.get_path()?.to_path_buf();
- let time = event.get_dtstart();
-
- Some(KhLine{ path, time })
- }
-
- pub fn to_string(&self) -> String {
- format!("{}", self)
- }
-
pub fn to_cal(&self) -> Result<IcalVCalendar, String> {
let mut calendar = fileutil::read_calendar_from_path(&self.path)?;
if let Some(time) = self.time {
@@ -54,6 +43,21 @@ impl KhLine {
}
}
+impl From<&IcalVEvent> for KhLine {
+ fn from(event: &IcalVEvent) -> Self {
+ let path = event.get_parent().unwrap().get_path().unwrap().to_path_buf();
+ let time = event.get_dtstart();
+
+ KhLine{ path, time }
+ }
+}
+
+impl From<&IcalVCalendar> for KhLine {
+ fn from(cal: &IcalVCalendar) -> Self {
+ KhLine::from(&cal.get_principal_event())
+ }
+}
+
impl fmt::Display for KhLine {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let path_string = self.get_normalized_path().to_string_lossy();
@@ -94,7 +98,7 @@ mod tests {
let path = PathBuf::from("test/path");
let cal = IcalVCalendar::from_str(testdata::TEST_EVENT_MULTIDAY_ALLDAY, Some(&path)).unwrap();
let khline = KhLine::from(&cal.get_principal_event());
- assert_eq!(String::from("1182988800 test/path"), khline.unwrap().to_string());
+ assert_eq!(String::from("1182988800 test/path"), khline.to_string());
}
// #[test]