imgboard/src/state.rs

22 lines
533 B
Rust
Raw Normal View History

2023-10-19 17:24:08 +02:00
use axum::{extract::{FromRef, FromRequestParts}, async_trait, http::request::Parts};
2023-10-18 17:17:53 +02:00
use sqlx::{postgres::Postgres, Pool};
2023-10-19 17:24:08 +02:00
#[derive(Clone, FromRef)]
2023-10-18 17:17:53 +02:00
pub struct AppState {
pub pool: Pool<Postgres>,
2023-10-18 22:32:37 +02:00
pub hbs: handlebars::Handlebars<'static>,
2023-10-18 17:17:53 +02:00
}
2023-10-19 17:24:08 +02:00
#[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))
}
}