feat: Add support for Submillisecond web framework (#419)
* feat: Add support for Submillisecond web framework Adds support for Submillisecond, a Lunatic web framework * fix: Add submillisecond as doctest feature flag - adds submillisecond as a feature flag for maud for doctests * fix: Update formatting for submillisecond - fix formatting to match rustfmt for submillisecond_support * Add missing line break --------- Co-authored-by: Chris Wong <lambda.fairy@gmail.com>
This commit is contained in:
parent
1a2fefe4e5
commit
d46ce8c23a
4 changed files with 59 additions and 1 deletions
|
@ -8,6 +8,7 @@ Maud includes support for these web frameworks: [Actix], [Rocket], [Rouille], [T
|
|||
[Tide]: https://docs.rs/tide/
|
||||
[Axum]: https://docs.rs/axum/
|
||||
[Warp]: https://seanmonstar.com/blog/warp/
|
||||
[Submillisecond]: https://github.com/lunatic-solutions/submillisecond
|
||||
|
||||
# Actix
|
||||
|
||||
|
@ -197,3 +198,37 @@ async fn main() {
|
|||
warp::serve(hello).run(([127, 0, 0, 1], 8000)).await;
|
||||
}
|
||||
```
|
||||
|
||||
# Submillisecond
|
||||
|
||||
Submillisecond support is available with the "submillisecond" feature:
|
||||
|
||||
```toml
|
||||
# ...
|
||||
[dependencies]
|
||||
maud = { version = "*", features = ["submillisecond"] }
|
||||
# ...
|
||||
```
|
||||
|
||||
This adds an implementation of `IntoResponse` for `Markup`/`PreEscaped<String>`.
|
||||
This then allows you to use it directly as a response!
|
||||
|
||||
```rust,no_run
|
||||
use maud::{html, Markup};
|
||||
use std::io::Result;
|
||||
use submillisecond::{router, Application};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
Application::new(router! {
|
||||
|
||||
GET "/hello" => helloworld
|
||||
})
|
||||
.serve("0.0.0.0:3000")
|
||||
}
|
||||
|
||||
fn helloworld() -> Markup {
|
||||
html! {
|
||||
h1 { "Hello, World!" }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -7,10 +7,11 @@ edition = "2021"
|
|||
[dependencies]
|
||||
actix-web = { version = "4.0.0-rc.2", default-features = false, features = ["macros"] }
|
||||
ammonia = "3"
|
||||
maud = { path = "../maud", features = ["actix-web", "rocket", "tide", "axum", "warp"] }
|
||||
maud = { path = "../maud", features = ["actix-web", "rocket", "tide", "axum", "warp", "submillisecond"] }
|
||||
pulldown-cmark = "0.8"
|
||||
rocket = "0.5"
|
||||
rouille = "3"
|
||||
submillisecond = "0.4.1"
|
||||
tide = "0.16"
|
||||
tokio = { version = "1.9.0", features = ["rt", "macros", "rt-multi-thread"] }
|
||||
axum = "0.7"
|
||||
|
|
|
@ -27,6 +27,7 @@ futures-util = { version = "0.3.0", optional = true, default-features = false }
|
|||
actix-web-dep = { package = "actix-web", version = "4", optional = true, default-features = false }
|
||||
tide = { version = "0.16.0", optional = true, default-features = false }
|
||||
axum-core = { version = "0.4", optional = true }
|
||||
submillisecond = { version = "0.4.1", optional = true }
|
||||
http = { version = "1", optional = true }
|
||||
warp = { version = "0.3.6", optional = true }
|
||||
|
||||
|
|
|
@ -366,6 +366,27 @@ mod warp_support {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "submillisecond")]
|
||||
mod submillisecond_support {
|
||||
use crate::PreEscaped;
|
||||
use alloc::string::String;
|
||||
use submillisecond::{
|
||||
http::{header, HeaderMap, HeaderValue},
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
|
||||
impl IntoResponse for PreEscaped<String> {
|
||||
fn into_response(self) -> Response {
|
||||
let mut headers = HeaderMap::new();
|
||||
headers.insert(
|
||||
header::CONTENT_TYPE,
|
||||
HeaderValue::from_static("text/html; charset=utf-8"),
|
||||
);
|
||||
(headers, self.0).into_response()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub mod macro_private {
|
||||
use crate::{display, Render};
|
||||
|
|
Loading…
Add table
Reference in a new issue