use std::sync::Arc; use sqlx::PgPool; use stack_up::{Configuration, cache::RedisManager}; use crate::cnfg::LocalConfig; #[derive(Clone)] pub struct AppHandle(Arc); impl std::ops::Deref for AppHandle { type Target = Arc; fn deref(&self) -> &Self::Target { &self.0 } } #[derive(Clone)] pub struct Services { pub postgres: PgPool, pub cache: RedisManager, } pub struct AppState { pub services: Services, pub local_config: LocalConfig, } impl AppState { pub async fn create( services: Services, configuration: &Configuration, ) -> Result { let local_config: LocalConfig = serde_json::from_value(configuration.misc.clone())?; Ok(AppHandle(Arc::new(Self { services, local_config, }))) } }