From 5f608c737e6229896d5f7ce9db6b17c95b91d667 Mon Sep 17 00:00:00 2001 From: Coleman McFarland Date: Mon, 11 Jun 2018 14:05:35 -0700 Subject: [PATCH] impl Responder for actix-web framework It looks similar to the Rocket implementation, and functionally is also similar: a syncronous response for PreEscaped Refs #135 --- maud/Cargo.toml | 1 + maud/src/lib.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/maud/Cargo.toml b/maud/Cargo.toml index ab40265a..7feca8f3 100644 --- a/maud/Cargo.toml +++ b/maud/Cargo.toml @@ -17,6 +17,7 @@ maud_htmlescape = { version = "0.17.0", path = "../maud_htmlescape" } maud_macros = { version = "0.17.5", path = "../maud_macros" } iron = { version = ">= 0.5.1, < 0.7.0", optional = true } rocket = { version = "0.3", optional = true } +actix-web = { version = "0.6.12", optional = true } [dev-dependencies] maud_lints = { version = "0.17.0", path = "../maud_lints" } diff --git a/maud/src/lib.rs b/maud/src/lib.rs index 0a245ab2..8dc7410d 100644 --- a/maud/src/lib.rs +++ b/maud/src/lib.rs @@ -10,6 +10,7 @@ #![doc(html_root_url = "https://docs.rs/maud/0.17.5")] +#[cfg(feature = "actix-web")] extern crate actix_web; #[cfg(feature = "iron")] extern crate iron; #[cfg(feature = "rocket")] extern crate rocket; @@ -189,3 +190,17 @@ mod rocket_support { } } } + +#[cfg(feature = "actix-web")] +mod actix_support { + use PreEscaped; + use actix_web::{Responder, HttpResponse, HttpRequest, Error}; + + impl Responder for PreEscaped { + type Item = HttpResponse; + type Error = Error; + fn respond_to(self, _req: &HttpRequest) -> Result { + Ok(HttpResponse::Ok().body(self.0)) + } + } +}