cja/server/page/
factory.rs1use axum::{extract::FromRequestParts, http::request::Parts, response::Response};
2use maud::Render;
3
4use crate::app_state::AppState;
5
6use super::Page;
7
8pub struct Factory<A: AppState> {
9 #[allow(dead_code)]
10 state: A,
11}
12
13impl<A: AppState> Factory<A> {
14 pub fn create_page<C: Render + 'static>(self, content: C) -> Page {
15 Page {
16 content: Box::new(content),
17 }
18 }
19}
20
21impl<A: AppState> FromRequestParts<A> for Factory<A> {
22 type Rejection = Response;
23
24 async fn from_request_parts(_: &mut Parts, state: &A) -> Result<Self, Self::Rejection> {
25 Ok(Self {
26 state: state.clone(),
27 })
28 }
29}