diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/app/mod.rs | 4 | ||||
| -rw-r--r-- | src/app/store/mod.rs | 21 |
2 files changed, 20 insertions, 5 deletions
diff --git a/src/app/mod.rs b/src/app/mod.rs index 7bb9c72..4e2b0d7 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -2,7 +2,7 @@ mod ledger; mod store; use miette::{Diagnostic, ErrReport, Result}; -use store::{Context, Store}; +use store::{AppContext, Store}; use thiserror::Error; #[derive(Debug, Default, PartialEq)] @@ -29,7 +29,7 @@ impl std::fmt::Display for AppMode { #[derive(Default)] pub struct App { - context: Context, + context: AppContext, error: Option<ErrReport>, mode: AppMode, } diff --git a/src/app/store/mod.rs b/src/app/store/mod.rs index cbec171..5b06eb1 100644 --- a/src/app/store/mod.rs +++ b/src/app/store/mod.rs @@ -5,6 +5,8 @@ use miette::{Diagnostic, Result}; use sqlite::SQLiteStore; use thiserror::Error; +use records::{EquityChangeEvent, EquitySymbol, FiduciaryAccount}; + pub enum Context { SQLite(SQLiteStore), } @@ -23,21 +25,34 @@ impl Default for Context { } } +pub struct AppContext { + context: Context, + accounts: Vec<FiduciaryAccount>, + symbols: Vec<EquitySymbol>, + events: Vec<EquityChangeEvent>, +} + +impl Default for AppContext { + fn default() -> Self { + AppContext { context: Context::default(), accounts: vec![], symbols: vec![], events: vec![] } + } +} + pub trait Store { fn init(&mut self) -> Result<(), ContextError>; fn get_counter(&self) -> Result<u8, ContextError>; fn set_counter(&mut self, new_count: u8) -> Result<u8, ContextError>; } -impl Context { +impl AppContext { pub fn unwrap_store(&mut self) -> &mut impl Store { - match self { + match &mut self.context { Context::SQLite(store) => store, } } pub fn get_store(&self) -> &impl Store { - match self { + match &self.context { Context::SQLite(store) => store, } } |
