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 fn from_request_parts(
25 _: &mut Parts,
26 state: &A,
27 ) -> impl Future<Output = Result<Self, Self::Rejection>> {
28 std::future::ready(Ok(Self {
29 state: state.clone(),
30 }))
31 }
32}