// // Copyright 2021, Jesús Pérez Lorenzo // use core::fmt; // use futures::lock::Mutex; // use std::sync::Arc; // use lazy_static::lazy_static; // use once_cell::sync::Lazy; use std::sync::Arc; // use tokio::sync::Mutex; use parking_lot::RwLock; use serde::Deserialize; pub mod appdata; pub mod appenv; pub mod appinfo; pub mod config; pub mod module; pub mod profile; use crate::appdata::AppData; use AppRunMode::*; pub type BxDynResult = std::result::Result>; #[derive(Clone, Debug)] pub struct AppStore { pub app_data: Arc>, } impl AppStore { pub fn new(app: AppData) -> Self { AppStore { app_data: Arc::new(RwLock::new(app)), } } } /* /// So we don't have to tackle how different database work, we'll just use /// a simple in-memory DB, a vector synchronized by a mutex. pub type Db = Arc>>; #[must_use] pub fn blank_db() -> Db { Arc::new(Mutex::new(Vec::new())) // Vec::new())) //Arc::new(Mutex::new(vec!(AppData::new(AppEnv::default())))) // Vec::new())) } #[must_use] pub fn appdata_db(env: AppEnv) -> Db { Arc::new(Mutex::new(vec!(AppData::new(env)))) } pub static DB: Lazy = Lazy::new(|| blank_db()); pub async fn get_db_appdata() -> AppData { let db_appdata = DB.lock().await; db_appdata[0].to_owned() } */ #[derive(Clone, Copy, Debug, PartialEq)] /// `DataStore` options pub enum AppRunMode { Basic, // Free basic mode Pro, // Pro licensed mode Premium, // Premium licensed mode Unknown, } pub type OptionAppRunMode = Option; impl Default for AppRunMode { fn default() -> Self { Unknown } } #[allow(clippy::pattern_type_mismatch)] impl fmt::Display for AppRunMode { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Basic => write!(f, "basic"), Pro => write!(f, "pro"), Premium => write!(f, "premium"), Unknown => write!(f, "Unknown"), } } } impl AppRunMode { /// Get `DataStore`from String to enum #[must_use] pub fn get_from(str: &str) -> AppRunMode { match str { "basic" => Basic, "pro" => Pro, "premium" => Premium, _ => Unknown, } } } #[derive(Clone, Debug, Default, Deserialize)] pub struct DataCollUsers { pub fields: String, } #[derive(Clone, Debug)] pub struct Zterton { pub protocol: String, pub host: String, pub port: u16, } impl Default for Zterton { fn default() -> Self { Self { protocol: String::from("http"), host: String::from("127.0.0.1"), port: 8000, } } } impl Zterton { #[must_use] /// New Zterton definition pub fn new(protocol: String, host: String, port: u16) -> Self { Zterton { protocol, host, port, } } }