diff options
author | Akshay <[email protected]> | 2020-07-14 12:50:36 +0100 |
---|---|---|
committer | Akshay <[email protected]> | 2020-07-14 12:50:36 +0100 |
commit | 3ded40d04f49983e7907366536dbc94917cee666 (patch) | |
tree | 5e837246e3603249c9a7e4343d1afb762d5d0e71 /src/habit/bit.rs | |
parent | 68ebbd1f753e0937bfaf07006daf1d6144c21bed (diff) |
more boilerplate for auto-trackable habits
add funding.yml also :^)
Diffstat (limited to 'src/habit/bit.rs')
-rw-r--r-- | src/habit/bit.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/habit/bit.rs b/src/habit/bit.rs index 292b96a..3386182 100644 --- a/src/habit/bit.rs +++ b/src/habit/bit.rs | |||
@@ -3,6 +3,7 @@ use std::collections::HashMap; | |||
3 | use chrono::NaiveDate; | 3 | use chrono::NaiveDate; |
4 | use serde::{Deserialize, Serialize}; | 4 | use serde::{Deserialize, Serialize}; |
5 | 5 | ||
6 | use crate::habit::prelude::default_auto; | ||
6 | use crate::habit::traits::Habit; | 7 | use crate::habit::traits::Habit; |
7 | use crate::habit::{TrackEvent, ViewMode}; | 8 | use crate::habit::{TrackEvent, ViewMode}; |
8 | use crate::CONFIGURATION; | 9 | use crate::CONFIGURATION; |
@@ -37,6 +38,9 @@ pub struct Bit { | |||
37 | stats: HashMap<NaiveDate, CustomBool>, | 38 | stats: HashMap<NaiveDate, CustomBool>, |
38 | goal: CustomBool, | 39 | goal: CustomBool, |
39 | 40 | ||
41 | #[serde(default = "default_auto")] | ||
42 | auto: bool, | ||
43 | |||
40 | #[serde(skip)] | 44 | #[serde(skip)] |
41 | view_month_offset: u32, | 45 | view_month_offset: u32, |
42 | 46 | ||
@@ -45,11 +49,12 @@ pub struct Bit { | |||
45 | } | 49 | } |
46 | 50 | ||
47 | impl Bit { | 51 | impl Bit { |
48 | pub fn new(name: impl AsRef<str>) -> Self { | 52 | pub fn new(name: impl AsRef<str>, auto: bool) -> Self { |
49 | return Bit { | 53 | return Bit { |
50 | name: name.as_ref().to_owned(), | 54 | name: name.as_ref().to_owned(), |
51 | stats: HashMap::new(), | 55 | stats: HashMap::new(), |
52 | goal: CustomBool(true), | 56 | goal: CustomBool(true), |
57 | auto, | ||
53 | view_month_offset: 0, | 58 | view_month_offset: 0, |
54 | view_mode: ViewMode::Day, | 59 | view_mode: ViewMode::Day, |
55 | }; | 60 | }; |
@@ -114,4 +119,7 @@ impl Habit for Bit { | |||
114 | fn view_mode(&self) -> ViewMode { | 119 | fn view_mode(&self) -> ViewMode { |
115 | self.view_mode | 120 | self.view_mode |
116 | } | 121 | } |
122 | fn is_auto(&self) -> bool { | ||
123 | self.auto | ||
124 | } | ||
117 | } | 125 | } |