aboutsummaryrefslogtreecommitdiff
path: root/src/habit.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-02-11 15:44:20 +0000
committerAkshay <[email protected]>2020-02-11 15:44:20 +0000
commit036357bc3c6227ac747c89cc82c29ef6a940ccbe (patch)
treed21d4a45b77395136e232e8a541e4e3ea642e307 /src/habit.rs
parentecc2e2b296c4241b56d201012d7a7de5f96007db (diff)
serialize dates, remove cruft
Diffstat (limited to 'src/habit.rs')
-rw-r--r--src/habit.rs6
1 files changed, 2 insertions, 4 deletions
diff --git a/src/habit.rs b/src/habit.rs
index 967e425..6445545 100644
--- a/src/habit.rs
+++ b/src/habit.rs
@@ -1,8 +1,9 @@
1use std::collections::HashMap; 1use std::collections::HashMap;
2 2
3use chrono::NaiveDate; 3use chrono::NaiveDate;
4use serde::Serialize;
4 5
5#[derive(Debug)] 6#[derive(Serialize, Debug)]
6pub struct Habit<T> { 7pub struct Habit<T> {
7 name: String, 8 name: String,
8 stats: HashMap<NaiveDate, T>, 9 stats: HashMap<NaiveDate, T>,
@@ -20,15 +21,12 @@ where
20 goal, 21 goal,
21 }; 22 };
22 } 23 }
23
24 pub fn get_name(&self) -> String { 24 pub fn get_name(&self) -> String {
25 return self.name.to_owned(); 25 return self.name.to_owned();
26 } 26 }
27
28 pub fn get_by_date(&self, date: NaiveDate) -> Option<&T> { 27 pub fn get_by_date(&self, date: NaiveDate) -> Option<&T> {
29 self.stats.get(&date) 28 self.stats.get(&date)
30 } 29 }
31
32 pub fn insert_entry(&mut self, date: NaiveDate, val: T) { 30 pub fn insert_entry(&mut self, date: NaiveDate, val: T) {
33 *self.stats.entry(date).or_insert(val) = val; 31 *self.stats.entry(date).or_insert(val) = val;
34 } 32 }