Skip to content

Commit 320add8

Browse files
Warp Integration: Yet another web framework support (#404)
* Add warp integration. * Add warp to docs * Update changelog * Please the mighty rustfmt \o/ * Enable warp feature in doctest --------- Co-authored-by: Chris Wong <lambda.fairy@gmail.com>
1 parent b3a98c9 commit 320add8

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
[#396](https://github.com/lambda-fairy/maud/pull/396)
1111
- Support `axum` v0.7 through `axum-core` v0.4 and `http` v1
1212
[#401](https://github.com/lambda-fairy/maud/pull/401)
13+
- Add support for `warp` v0.3.6
14+
[#404](https://github.com/lambda-fairy/maud/pull/404)
1315
- Support `rocket` v0.5
1416
[#406](https://github.com/lambda-fairy/maud/pull/406)
1517

docs/content/web-frameworks.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Maud includes support for these web frameworks: [Actix], [Rocket], [Rouille], [T
77
[Rouille]: https://github.com/tomaka/rouille
88
[Tide]: https://docs.rs/tide/
99
[Axum]: https://docs.rs/axum/
10+
[Warp]: https://seanmonstar.com/blog/warp/
1011

1112
# Actix
1213

@@ -171,3 +172,28 @@ async fn main() {
171172
axum::serve(listener, app.into_make_service()).await.unwrap();
172173
}
173174
```
175+
176+
# Warp
177+
178+
Warp support is available with the "warp" feature:
179+
180+
```toml
181+
# ...
182+
[dependencies]
183+
maud = { version = "*", features = ["warp"] }
184+
# ...
185+
```
186+
187+
This enables `Markup` to be of type `warp::Reply`, making it possible to return it
188+
immediately from a handler.
189+
190+
```rust,no_run
191+
use maud::html;
192+
use warp::Filter;
193+
194+
#[tokio::main]
195+
async fn main() {
196+
let hello = warp::any().map(|| html! { h1 { "Hello, world!" } });
197+
warp::serve(hello).run(([127, 0, 0, 1], 8000)).await;
198+
}
199+
```

doctest/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ edition = "2021"
77
[dependencies]
88
actix-web = { version = "4.0.0-rc.2", default-features = false, features = ["macros"] }
99
ammonia = "3"
10-
maud = { path = "../maud", features = ["actix-web", "rocket", "tide", "axum"] }
10+
maud = { path = "../maud", features = ["actix-web", "rocket", "tide", "axum", "warp"] }
1111
pulldown-cmark = "0.8"
1212
rocket = "0.5"
1313
rouille = "3"
1414
tide = "0.16"
1515
tokio = { version = "1.9.0", features = ["rt", "macros", "rt-multi-thread"] }
1616
axum = "0.7"
17+
warp = "0.3.6"
1718

1819
[dependencies.async-std]
1920
version = "1.9.0"

maud/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ actix-web-dep = { package = "actix-web", version = "4", optional = true, default
2727
tide = { version = "0.16.0", optional = true, default-features = false }
2828
axum-core = { version = "0.4", optional = true }
2929
http = { version = "1", optional = true }
30+
warp = { version = "0.3.6", optional = true }
3031

3132
[dev-dependencies]
3233
trybuild = { version = "1.0.33", features = ["diff"] }

maud/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,19 @@ mod axum_support {
353353
}
354354
}
355355

356+
#[cfg(feature = "warp")]
357+
mod warp_support {
358+
use crate::PreEscaped;
359+
use alloc::string::String;
360+
use warp::reply::{self, Reply, Response};
361+
362+
impl Reply for PreEscaped<String> {
363+
fn into_response(self) -> Response {
364+
reply::html(self.into_string()).into_response()
365+
}
366+
}
367+
}
368+
356369
#[doc(hidden)]
357370
pub mod macro_private {
358371
use crate::{display, Render};

0 commit comments

Comments
 (0)