Skip to content

Commit

Permalink
Add actix-web v3 support (#228)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
robjtede and lambda-fairy authored Oct 11, 2020
1 parent b3d16f8 commit 31115a6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 7 additions & 3 deletions maud/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -33,3 +33,7 @@ travis-ci = { repository = "lambda-fairy/maud" }

[package.metadata.docs.rs]
all-features = true

[[example]]
name = "actix"
required-features = ["actix-web"]
25 changes: 25 additions & 0 deletions maud/examples/actix.rs
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 1 addition & 8 deletions maud/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 31115a6

Please sign in to comment.