From 5575a739e3eaa34bb8ee433c68273b46655420fc Mon Sep 17 00:00:00 2001 From: thatguydoru Date: Sat, 2 Dec 2023 07:12:22 +0800 Subject: [PATCH 1/5] Add warp integration. --- CHANGELOG.md | 2 ++ doctest/Cargo.toml | 1 + maud/Cargo.toml | 1 + maud/src/lib.rs | 13 +++++++++++++ 4 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60f636d2..619f0189 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ [#380](https://github.com/lambda-fairy/maud/pull/380) - Accept literals in attribute names [#396](https://github.com/lambda-fairy/maud/pull/396) +- Add support for `warp` v0.3.6 + [#]() ## [0.25.0] - 2023-04-16 diff --git a/doctest/Cargo.toml b/doctest/Cargo.toml index 35df0a43..1a2540e2 100644 --- a/doctest/Cargo.toml +++ b/doctest/Cargo.toml @@ -14,6 +14,7 @@ rouille = "3" tide = "0.16" tokio = { version = "1.9.0", features = ["rt", "macros", "rt-multi-thread"] } axum = "0.6" +warp = "0.3.6" [dependencies.async-std] version = "1.9.0" diff --git a/maud/Cargo.toml b/maud/Cargo.toml index d9088537..c3cac36b 100644 --- a/maud/Cargo.toml +++ b/maud/Cargo.toml @@ -27,6 +27,7 @@ actix-web-dep = { package = "actix-web", version = "4", optional = true, default tide = { version = "0.16.0", optional = true, default-features = false } axum-core = { version = "0.3", optional = true } http = { version = "0.2", optional = true } +warp = { version = "0.3.6", optional = true } [dev-dependencies] trybuild = { version = "1.0.33", features = ["diff"] } diff --git a/maud/src/lib.rs b/maud/src/lib.rs index 53aa3fa9..60954e61 100644 --- a/maud/src/lib.rs +++ b/maud/src/lib.rs @@ -353,6 +353,19 @@ mod axum_support { } } +#[cfg(feature = "warp")] +mod warp_support { + use crate::PreEscaped; + use alloc::string::String; + use warp::reply::{self, Response, Reply}; + + impl Reply for PreEscaped { + fn into_response(self) -> Response { + reply::html(self.into_string()).into_response() + } + } +} + #[doc(hidden)] pub mod macro_private { use crate::{display, Render}; From 4026a11facc5f9f033d9e008c119e71d0516da0c Mon Sep 17 00:00:00 2001 From: thatguydoru Date: Sat, 2 Dec 2023 08:17:47 +0800 Subject: [PATCH 2/5] Add warp to docs --- docs/content/web-frameworks.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/content/web-frameworks.md b/docs/content/web-frameworks.md index 3579f1af..cf11cc3e 100644 --- a/docs/content/web-frameworks.md +++ b/docs/content/web-frameworks.md @@ -7,6 +7,7 @@ Maud includes support for these web frameworks: [Actix], [Rocket], [Rouille], [T [Rouille]: https://github.com/tomaka/rouille [Tide]: https://docs.rs/tide/ [Axum]: https://docs.rs/axum/ +[Warp]: https://seanmonstar.com/blog/warp/ # Actix @@ -173,3 +174,28 @@ async fn main() { .unwrap(); } ``` + +# Warp + +Warp support is available with the "warp" feature: + +```toml +# ... +[dependencies] +maud = { version = "*", features = ["warp"] } +# ... +``` + +This enables `Markup` to be of type `warp::Reply`, making it possible to return it +immediately from a handler. + +```rust,no_run +use maud::html; +use warp::Filter; + +#[tokio::main] +async fn main() { + let hello = warp::any().map(|| html! { h1 { "Hello, world!" } }); + warp::serve(hello).run(([127, 0, 0, 1], 8000)).await; +} +``` From 7f2c525107d9a042bd1d54880359012776a07125 Mon Sep 17 00:00:00 2001 From: thatguydoru Date: Sat, 2 Dec 2023 08:24:22 +0800 Subject: [PATCH 3/5] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 619f0189..db3c80b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ - Accept literals in attribute names [#396](https://github.com/lambda-fairy/maud/pull/396) - Add support for `warp` v0.3.6 - [#]() + [#404](https://github.com/lambda-fairy/maud/pull/404) ## [0.25.0] - 2023-04-16 From cb8e64408514d808cb07b095d5c7960c4b1db971 Mon Sep 17 00:00:00 2001 From: thatguydoru Date: Sat, 2 Dec 2023 08:27:03 +0800 Subject: [PATCH 4/5] Please the mighty rustfmt \o/ --- maud/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maud/src/lib.rs b/maud/src/lib.rs index 60954e61..fa37cabf 100644 --- a/maud/src/lib.rs +++ b/maud/src/lib.rs @@ -357,7 +357,7 @@ mod axum_support { mod warp_support { use crate::PreEscaped; use alloc::string::String; - use warp::reply::{self, Response, Reply}; + use warp::reply::{self, Reply, Response}; impl Reply for PreEscaped { fn into_response(self) -> Response { From f077f0b6872438a86310f075f0556a2b07b7e8ed Mon Sep 17 00:00:00 2001 From: thatguydoru Date: Sat, 2 Dec 2023 08:31:39 +0800 Subject: [PATCH 5/5] Enable warp feature in doctest --- doctest/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doctest/Cargo.toml b/doctest/Cargo.toml index 1a2540e2..3de0686c 100644 --- a/doctest/Cargo.toml +++ b/doctest/Cargo.toml @@ -7,7 +7,7 @@ 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"] } +maud = { path = "../maud", features = ["actix-web", "rocket", "tide", "axum", "warp"] } pulldown-cmark = "0.8" rocket = "0.4" rouille = "3"