|
- use std::ops::Deref;
- use std::sync::Arc;
-
- use sqlx::PgPool;
-
- use crate::config::AppConfig;
-
- #[derive(Clone)]
- pub struct AppState(pub(crate) Arc<InnerState>);
-
- pub struct InnerState {
- pub config: AppConfig,
- pub db: PgPool,
- pub client: reqwest::Client,
- }
-
- impl AppState {
- pub fn new(config: AppConfig, db: PgPool, client: reqwest::Client) -> Self {
- Self(Arc::new(InnerState { config, db, client }))
- }
-
- pub fn db(&self) -> &PgPool {
- &self.0.db
- }
-
- pub fn config(&self) -> &AppConfig {
- &self.0.config
- }
- }
-
- impl Deref for AppState {
- type Target = InnerState;
-
- fn deref(&self) -> &Self::Target {
- &self.0
- }
- }
|