aboutsummaryrefslogtreecommitdiff
path: root/src/habit/traits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/habit/traits.rs')
-rw-r--r--src/habit/traits.rs20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/habit/traits.rs b/src/habit/traits.rs
index 24d941d..54ec9e1 100644
--- a/src/habit/traits.rs
+++ b/src/habit/traits.rs
@@ -2,10 +2,10 @@ use chrono::NaiveDate;
2use cursive::direction::Direction; 2use cursive::direction::Direction;
3use cursive::event::{Event, EventResult}; 3use cursive::event::{Event, EventResult};
4use cursive::{Printer, Vec2}; 4use cursive::{Printer, Vec2};
5
6use typetag; 5use typetag;
7 6
8use crate::habit::{Bit, Count, InnerData, TrackEvent}; 7use crate::command::GoalKind;
8use crate::habit::{Bit, Count, Float, InnerData, TrackEvent};
9use crate::views::ShadowView; 9use crate::views::ShadowView;
10 10
11pub trait Habit { 11pub trait Habit {
@@ -20,6 +20,7 @@ pub trait Habit {
20 fn remaining(&self, date: NaiveDate) -> u32; 20 fn remaining(&self, date: NaiveDate) -> u32;
21 fn set_goal(&mut self, goal: Self::HabitType); 21 fn set_goal(&mut self, goal: Self::HabitType);
22 fn set_name(&mut self, name: impl AsRef<str>); 22 fn set_name(&mut self, name: impl AsRef<str>);
23 fn kind(&self) -> GoalKind;
23 24
24 fn inner_data_ref(&self) -> &InnerData; 25 fn inner_data_ref(&self) -> &InnerData;
25 fn inner_data_mut_ref(&mut self) -> &mut InnerData; 26 fn inner_data_mut_ref(&mut self) -> &mut InnerData;
@@ -31,6 +32,7 @@ pub trait Habit {
31pub trait HabitWrapper: erased_serde::Serialize { 32pub trait HabitWrapper: erased_serde::Serialize {
32 fn draw(&self, printer: &Printer); 33 fn draw(&self, printer: &Printer);
33 fn goal(&self) -> u32; 34 fn goal(&self) -> u32;
35 fn kind(&self) -> GoalKind;
34 fn modify(&mut self, date: NaiveDate, event: TrackEvent); 36 fn modify(&mut self, date: NaiveDate, event: TrackEvent);
35 fn name(&self) -> String; 37 fn name(&self) -> String;
36 fn on_event(&mut self, event: Event) -> EventResult; 38 fn on_event(&mut self, event: Event) -> EventResult;
@@ -69,6 +71,9 @@ macro_rules! auto_habit_impl {
69 fn goal(&self) -> u32 { 71 fn goal(&self) -> u32 {
70 Habit::goal(self) 72 Habit::goal(self)
71 } 73 }
74 fn kind(&self) -> GoalKind {
75 Habit::kind(self)
76 }
72 fn modify(&mut self, date: NaiveDate, event: TrackEvent) { 77 fn modify(&mut self, date: NaiveDate, event: TrackEvent) {
73 Habit::modify(self, date, event); 78 Habit::modify(self, date, event);
74 } 79 }
@@ -88,5 +93,12 @@ macro_rules! auto_habit_impl {
88 }; 93 };
89} 94}
90 95
91auto_habit_impl!(Count); 96macro_rules! generate_implementations {
92auto_habit_impl!(Bit); 97 ($($x:ident),*) => (
98 $(
99 auto_habit_impl!($x);
100 )*
101 );
102}
103
104generate_implementations!(Count, Bit, Float);