Add axum support
This commit is contained in:
parent
d18f9d2171
commit
2b1fefe882
6 changed files with 656 additions and 1 deletions
15
src/axum.rs
Normal file
15
src/axum.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use axum::{
|
||||
http::StatusCode,
|
||||
response::{Html, IntoResponse},
|
||||
};
|
||||
|
||||
use crate::{Document, Render};
|
||||
|
||||
impl IntoResponse for Document {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
match self.render_to_string() {
|
||||
Ok(html) => Html(html).into_response(),
|
||||
Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -105,3 +105,9 @@ impl Element {
|
|||
/// A `Document(el)` is basically the same as `[Content::doctype(), el.into()]`
|
||||
/// for the purposes of the [`crate::Render`] trait.
|
||||
pub struct Document(pub Element);
|
||||
|
||||
impl From<Element> for Document {
|
||||
fn from(value: Element) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
//!
|
||||
//! [hiccup]: https://github.com/weavejester/hiccup
|
||||
|
||||
#[cfg(feature = "axum")]
|
||||
mod axum;
|
||||
mod check;
|
||||
mod element;
|
||||
pub mod html;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue