pub mod engines;
use axum::{async_trait, extract::FromRequestParts, http::request::Parts, Extension};
use serde::Serialize;
use crate::Result;
#[cfg(feature = "with-db")]
pub mod pagination;
pub trait ViewRenderer {
fn render<S: Serialize>(&self, key: &str, data: S) -> Result<String>;
}
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct ViewEngine<E>(pub E);
impl<E> ViewEngine<E> {
pub fn new(engine: E) -> Self {
Self(engine)
}
}
impl<E> From<E> for ViewEngine<E> {
fn from(inner: E) -> Self {
Self::new(inner)
}
}
#[async_trait]
impl<S, E> FromRequestParts<S> for ViewEngine<E>
where
S: Send + Sync,
E: Clone + Send + Sync + 'static,
{
type Rejection = std::convert::Infallible;
async fn from_request_parts(
parts: &mut Parts,
state: &S,
) -> std::result::Result<Self, Self::Rejection> {
let Extension(tl): Extension<Self> = Extension::from_request_parts(parts, state)
.await
.expect("TeraLayer missing. Is the TeraLayer installed?");
Ok(tl)
}
}