21 lines
533 B
Rust
21 lines
533 B
Rust
use axum::{extract::{FromRef, FromRequestParts}, async_trait, http::request::Parts};
|
|
use sqlx::{postgres::Postgres, Pool};
|
|
|
|
#[derive(Clone, FromRef)]
|
|
pub struct AppState {
|
|
pub pool: Pool<Postgres>,
|
|
pub hbs: handlebars::Handlebars<'static>,
|
|
}
|
|
|
|
#[async_trait]
|
|
impl<S> FromRequestParts<S> for AppState
|
|
where
|
|
Self: FromRef<S>,
|
|
S: Send + Sync,
|
|
{
|
|
type Rejection = &'static str;
|
|
|
|
async fn from_request_parts(_parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
|
|
Ok(Self::from_ref(state))
|
|
}
|
|
}
|