use std::fmt::Debug; use axum::{ async_trait, extract::{FromRef, FromRequestParts}, http::request::Parts, }; use sqlx::{Pool, Postgres}; use crate::Error; #[derive(Debug, Clone)] pub struct AppState { pub pool: Pool, pub jwt_secret: String, pub jwt_max_age: time::Duration, } impl AppState { pub fn new(pool: Pool, jwt_secret: String, jwt_max_age: time::Duration) -> Self { Self { pool, jwt_secret, jwt_max_age, } } } #[async_trait] impl FromRequestParts for AppState where Self: FromRef, S: Send + Sync + Debug, { type Rejection = Error; async fn from_request_parts(_parts: &mut Parts, state: &S) -> Result { Ok(Self::from_ref(state)) } }