From 31115a628733938e45cb33a0f1a18f7d3bb16fc4 Mon Sep 17 00:00:00 2001 From: Rob Ede <robjtede@icloud.com> Date: Sun, 11 Oct 2020 05:22:19 +0100 Subject: [PATCH] Add actix-web v3 support (#228) * Add actix-web v3 support * Add actix-web example * Resolve changelog PR number * Make sure that examples are built on CI * Format Cargo.toml consistently Co-authored-by: Chris Wong <lambda.fairy@gmail.com> --- .travis.yml | 2 +- CHANGELOG.md | 2 ++ maud/Cargo.toml | 10 +++++++--- maud/examples/actix.rs | 25 +++++++++++++++++++++++++ maud/src/lib.rs | 9 +-------- 5 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 maud/examples/actix.rs diff --git a/.travis.yml b/.travis.yml index bb1cf43..7d3b79f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ jobs: # build and rarely break. Speed up CI by checking them separately. - name: "All features" script: - - cargo check --workspace --all-features + - cargo check --workspace --all-features --all-targets - name: "Benchmarks" script: - (cd benchmarks && cargo test --benches --locked) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0643a12..940445d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Change Log ## [Unreleased] +- [Changed] Add support for Actix Web 3.0.0. Actix Web 2.0.0 support is retained. + [#228](https://github.com/lambda-fairy/maud/pull/228) ## [0.22.0] - 2020-06-20 - [Changed] Update Actix to 2.0.0. Actix 1.0.0 is no longer supported. diff --git a/maud/Cargo.toml b/maud/Cargo.toml index a80e3d0..f9812ef 100644 --- a/maud/Cargo.toml +++ b/maud/Cargo.toml @@ -15,15 +15,15 @@ edition = "2018" default = [] # Web framework integrations -actix-web = ["actix-web-dep", "futures"] +actix-web = ["actix-web-dep", "futures-util"] [dependencies] maud_htmlescape = { version = "0.17.0", path = "../maud_htmlescape" } maud_macros = { version = "0.22.0", path = "../maud_macros" } iron = { version = ">= 0.5.1, < 0.7.0", optional = true } rocket = { version = ">= 0.3, < 0.5", optional = true } -futures = { version = "0.3.0", optional = true } -actix-web-dep = { version = "2.0.0", optional = true, default-features = false, package = "actix-web" } +futures-util = { version = "0.3.0", optional = true, default-features = false } +actix-web-dep = { package = "actix-web", version = ">= 2, < 4", optional = true, default-features = false } [dev-dependencies] trybuild = { version = "1.0.33", features = ["diff"] } @@ -33,3 +33,7 @@ travis-ci = { repository = "lambda-fairy/maud" } [package.metadata.docs.rs] all-features = true + +[[example]] +name = "actix" +required-features = ["actix-web"] diff --git a/maud/examples/actix.rs b/maud/examples/actix.rs new file mode 100644 index 0000000..a4832b4 --- /dev/null +++ b/maud/examples/actix.rs @@ -0,0 +1,25 @@ +// do not use this line in your application +use actix_web_dep as actix_web; + +use actix_web::{get, App, HttpServer, Result as AwResult}; +use maud::{html, Markup}; +use std::io; + +#[get("/")] +async fn index() -> AwResult<Markup> { + Ok(html! { + html { + body { + h1 { "Hello World!" } + } + } + }) +} + +#[actix_web::main] +async fn main() -> io::Result<()> { + HttpServer::new(|| App::new().service(index)) + .bind(("127.0.0.1", 8080))? + .run() + .await +} diff --git a/maud/src/lib.rs b/maud/src/lib.rs index e1bb924..ae16c52 100644 --- a/maud/src/lib.rs +++ b/maud/src/lib.rs @@ -7,13 +7,6 @@ #![doc(html_root_url = "https://docs.rs/maud/0.22.0")] -#[cfg(feature = "actix-web")] -extern crate actix_web_dep; -#[cfg(feature = "iron")] -extern crate iron; -#[cfg(feature = "rocket")] -extern crate rocket; - use std::fmt::{self, Write}; pub use maud_macros::{html, html_debug}; @@ -218,7 +211,7 @@ mod rocket_support { mod actix_support { use crate::PreEscaped; use actix_web_dep::{Error, HttpRequest, HttpResponse, Responder}; - use futures::future::{ok, Ready}; + use futures_util::future::{ok, Ready}; impl Responder for PreEscaped<String> { type Error = Error;