graphul/template.rs
1use askama::Template;
2use axum::response::{Html, IntoResponse, Response};
3use hyper::StatusCode;
4
5pub struct HtmlTemplate<T>(pub T);
6
7impl<T> IntoResponse for HtmlTemplate<T>
8where
9 T: Template,
10{
11 fn into_response(self) -> Response {
12 match self.0.render() {
13 Ok(html) => Html(html).into_response(),
14 Err(err) => (
15 StatusCode::INTERNAL_SERVER_ERROR,
16 format!("Failed to render template. Error: {err}"),
17 )
18 .into_response(),
19 }
20 }
21}