Add actix-web v3 support ()

* 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>
This commit is contained in:
Rob Ede 2020-10-11 05:22:19 +01:00 committed by GitHub
parent b3d16f83b1
commit 31115a6287
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 12 deletions

View file

@ -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)

View file

@ -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.

View file

@ -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"]

25
maud/examples/actix.rs Normal file
View file

@ -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
}

View file

@ -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;