aboutsummaryrefslogtreecommitdiff
path: root/src/habit.rs
diff options
context:
space:
mode:
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 }