Expand description
axum integration for hemplate templates.
Wrap any Hemplate type in HtmlTemplate (or StatusTemplate) to
return it from an axum handler:
async fn home() -> HtmlTemplate<HomeView> {
HomeView { title: "Welcome".into() }.into()
}No blanket impl<T: Hemplate> IntoResponse for T exists — Rust’s coherence
rules forbid it (foreign trait + foreign type + overlap with axum’s existing
blanket impls). The wrapper is the canonical workaround, matching axum’s own
Json / Html / Form newtypes.
§hemplate-axum
Axum response wrappers for Hemplate views. Requires Rust 1.91 or newer.
[dependencies]
hemplate = "0.6.0"
hemplate-axum = "0.6.0"Every Hemplate package has the same version and pins the others exactly; use
hemplate and hemplate-axum of the same release.
use hemplate::{Hemplate, RenderError};
use hemplate_axum::{HemplateExt, HtmlTemplate};
struct HomePage;
impl Hemplate for HomePage {
fn render_into(&self, output: &mut dyn core::fmt::Write) -> Result<(), RenderError> {
output.write_str("<h1>Home</h1>")?;
Ok(())
}
}
assert_eq!(HomePage.render()?, "<h1>Home</h1>");
let response: HtmlTemplate<HomePage> = HomePage.into_html();The crate provides:
HtmlTemplate<T>for200 OKHTML responses;StatusTemplate<T>for HTML responses with an explicit status code;HemplateExtconvenience methods:into_html()andwith_status(...).
The wrappers depend only on hemplate-runtime; applications can use the normal
hemplate facade without pulling parser tooling into the response adapter.
§License
MIT
Structs§
- Html
Template - Wrapper that converts a
Hemplatetype into a 200 OK axumResponsewithContent-Type: text/html; charset=utf-8. - Status
Template - Wrapper for pairing a
Hemplatetype with an HTTP status code.
Traits§
- Hemplate
Ext - Ergonomic extension methods for any
Hemplatetype — chainable wrapper construction without naming the wrapper type at the call site.