use std::sync::Arc;
use arcature::auth::PasswordHasher;
use arcature::prelude::*;
#[derive(Clone)]
pub struct AppState {
pub db: Option<Db>,
pub jobs: Option<Jobs>,
pub cache: Option<Cache>,
pub storage: Option<Storage>,
pub mail: Option<Mailer>,
pub hasher: Arc<PasswordHasher>,
pub app_name: String,
pub app_url: String,
pub mail_from: String,
}
pub fn state_fn(
config: &crate::config::Config,
hasher: Arc<PasswordHasher>,
) -> Arc<dyn Fn(&Resources, &Lifecycle) -> AppState + Send + Sync> {
let app_name = config.app_name.clone();
let app_url = config.app_url.clone();
let mail_from = config.mail_from.clone();
Arc::new(move |res, _lc| AppState {
db: res.db().cloned(),
jobs: res.jobs().cloned(),
cache: res.cache().cloned(),
storage: res.storage().cloned(),
mail: res.mail().cloned(),
hasher: hasher.clone(),
app_name: app_name.clone(),
app_url: app_url.clone(),
mail_from: mail_from.clone(),
})
}