Skip to content

Commit 8e8e078

Browse files
committed
[actix-web] Add support for actix-web >= 2.0.0
In order to support both actix-web < 2.0.0 and >= 2.0.0 at the same time I added a feature actix-web-2, which enables the actix-web dependency with the respective version und the name active-web-2-dep and the futures dependency which is required(?) for implementing the Responder trait for >= 2.0.0. Thus the user of maud has the choice to use actix-web in the version they prefer.
1 parent c119dbc commit 8e8e078

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

maud/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ description = "Compile-time HTML templates."
1111
categories = ["template-engine"]
1212
edition = "2018"
1313

14+
[features]
15+
actix-web-2 = ["actix-web-2-dep", "futures"]
16+
1417
[dependencies]
1518
maud_htmlescape = { version = "0.17.0", path = "../maud_htmlescape" }
1619
maud_macros = { version = "0.21.0", path = "../maud_macros" }
1720
iron = { version = ">= 0.5.1, < 0.7.0", optional = true }
1821
rocket = { version = ">= 0.3, < 0.5", optional = true }
1922
actix-web = { version = "1.0.0", optional = true, default-features = false }
23+
actix-web-2-dep = { version = "2.0.0", optional = true, default-features = false, package = "actix-web" }
24+
futures = { version = "0.3.0", optional = true }
2025

2126
[dev-dependencies]
2227
compiletest_rs = { version = "0.3.19", features = ["stable"] }

maud/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,20 @@ mod actix_support {
206206
}
207207
}
208208
}
209+
210+
#[cfg(feature = "actix-web-2")]
211+
mod actix2_support {
212+
use crate::PreEscaped;
213+
use actix_web_2_dep::{Responder, HttpResponse, HttpRequest, Error};
214+
use futures::future::{ok, Ready};
215+
216+
impl Responder for PreEscaped<String> {
217+
type Error = Error;
218+
type Future = Ready<Result<HttpResponse, Self::Error>>;
219+
fn respond_to(self, _req: &HttpRequest) -> Self::Future {
220+
ok(HttpResponse::Ok()
221+
.content_type("text/html; charset=utf-8")
222+
.body(self.0))
223+
}
224+
}
225+
}

0 commit comments

Comments
 (0)