diff options
| author | Kevin Hoerr <kjhoerr@submelon.dev> | 2026-05-04 17:15:24 -0400 |
|---|---|---|
| committer | Kevin Hoerr <kjhoerr@submelon.dev> | 2026-05-04 17:15:24 -0400 |
| commit | 6e34ad603ee0639fdc83a71d5b6c5dfaf7c7d550 (patch) | |
| tree | 2e594ca263c4d2f146f3b0a409ab8542472ee01b /src/app/mod.rs | |
| parent | 397f8bd3fd1d36a9703b319c46db34b83950a9b2 (diff) | |
| download | equity-tracker-6e34ad603ee0639fdc83a71d5b6c5dfaf7c7d550.tar.gz equity-tracker-6e34ad603ee0639fdc83a71d5b6c5dfaf7c7d550.tar.bz2 equity-tracker-6e34ad603ee0639fdc83a71d5b6c5dfaf7c7d550.zip | |
Remove counter from store
Diffstat (limited to 'src/app/mod.rs')
| -rw-r--r-- | src/app/mod.rs | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/app/mod.rs b/src/app/mod.rs index 83531f9..299f82e 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -32,6 +32,7 @@ pub struct App { context: AppContext, error: Option<ErrReport>, mode: AppMode, + counter: Option<u8>, } #[derive(Diagnostic, Debug, Error, PartialEq)] @@ -48,6 +49,7 @@ impl App { let store = self.context.unwrap_store(); store.init()?; + self.counter = Some(0_u8); self.mode = AppMode::Counter; Ok(self) @@ -68,8 +70,7 @@ impl App { } pub fn decrement_counter(&mut self) -> Result<()> { - let store = self.context.unwrap_store(); - let count = store.get_counter()?; + let count = self.counter.unwrap(); tracing::event!(tracing::Level::TRACE, count, "Decrementing counter."); if count == 0 { @@ -78,14 +79,13 @@ impl App { } .into()) } else { - store.set_counter(count - 1)?; + self.counter = Some(count - 1); Ok(()) } } pub fn increment_counter(&mut self) -> Result<()> { - let store = self.context.unwrap_store(); - let count = store.get_counter()?; + let count = self.counter.unwrap(); tracing::event!(tracing::Level::TRACE, count, "Incrementing counter."); if count == u8::MAX { @@ -94,17 +94,13 @@ impl App { } .into()) } else { - store.set_counter(count + 1)?; + self.counter = Some(count + 1); Ok(()) } } pub fn display_counter(&self) -> String { - self.context - .get_store() - .get_counter() - .map(|u| u.to_string()) - .unwrap_or("Error".into()) + self.counter.map_or("Error".into(), |c| c.to_string()) } pub fn set_error(&mut self, error: ErrReport) -> Result<()> { @@ -158,7 +154,7 @@ mod counter_tests { use store::ContextError; fn get_count(app: &App) -> Result<u8, ContextError> { - app.context.get_store().get_counter() + Ok(app.counter.unwrap()) } #[test] @@ -252,7 +248,7 @@ mod counter_tests { fn increment_counter_error() { let mut app = App::default(); assert!(app.init_context().is_ok()); - assert!(app.context.unwrap_store().set_counter(u8::MAX).is_ok()); + app.counter = Some(u8::MAX); let res = app.increment_counter(); assert!(res.is_err()); |
