From 42d80ad6cdb1a4ff9ff8fcc088b25d5f7b66a393 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 21 Dec 2021 23:17:14 +0100 Subject: askama_actix: revert to actix-web v3 for release --- askama_actix/Cargo.toml | 9 ++++----- askama_actix/src/lib.rs | 12 ++++++------ askama_actix/tests/basic.rs | 6 +++--- askama_shared/src/generator.rs | 7 ++++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/askama_actix/Cargo.toml b/askama_actix/Cargo.toml index 06fd2b3..14e996b 100644 --- a/askama_actix/Cargo.toml +++ b/askama_actix/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "askama_actix" -version = "0.11.1" +version = "0.12.0" description = "Actix-Web integration for Askama templates" documentation = "https://docs.rs/askama" keywords = ["markup", "template", "jinja2", "html"] @@ -13,11 +13,10 @@ readme = "README.md" edition = "2018" [dependencies] -actix-web = { version = "4.0.0-beta.14", default-features = false } +actix-web = { version = "3", default-features = false } askama = { version = "0.11.0", path = "../askama", default-features = false, features = ["with-actix-web", "mime", "mime_guess"] } -bytes = { version = "1" } +bytes = { version = "0.5" } futures-util = { version = "0.3" } [dev-dependencies] -actix-rt = { version = "2", default-features = false } -actix-test = "0.1.0-beta.8" +actix-rt = { version = "1", default-features = false } diff --git a/askama_actix/src/lib.rs b/askama_actix/src/lib.rs index baf9fd6..d9ac62d 100644 --- a/askama_actix/src/lib.rs +++ b/askama_actix/src/lib.rs @@ -3,23 +3,23 @@ pub use askama::*; use bytes::BytesMut; -use actix_web::{error::ErrorInternalServerError, HttpResponse}; +use actix_web::{error::ErrorInternalServerError, Error, HttpResponse}; pub trait TemplateToResponse { - fn to_response(&self) -> HttpResponse; + fn to_response(&self) -> std::result::Result; } impl TemplateToResponse for T { - fn to_response(&self) -> HttpResponse { + fn to_response(&self) -> std::result::Result { let mut buffer = BytesMut::with_capacity(T::SIZE_HINT); if self.render_into(&mut buffer).is_err() { - return ErrorInternalServerError("Template parsing error").error_response(); + return Err(ErrorInternalServerError("Template parsing error")); } let ctype = askama::mime::extension_to_mime_type(T::EXTENSION.unwrap_or("txt")).to_string(); - HttpResponse::Ok() + Ok(HttpResponse::Ok() .content_type(ctype.as_str()) - .body(buffer.freeze()) + .body(buffer.freeze())) } } diff --git a/askama_actix/tests/basic.rs b/askama_actix/tests/basic.rs index 070cbf6..c540076 100644 --- a/askama_actix/tests/basic.rs +++ b/askama_actix/tests/basic.rs @@ -11,7 +11,7 @@ struct HelloTemplate<'a> { #[actix_rt::test] async fn test_actix_web() { - let srv = actix_test::start(|| { + let srv = actix_web::test::start(|| { actix_web::App::new() .service(web::resource("/").to(|| async { HelloTemplate { name: "world" } })) }); @@ -30,10 +30,10 @@ async fn test_actix_web() { #[actix_rt::test] async fn test_actix_web_responder() { - let srv = actix_test::start(|| { + let srv = actix_web::test::start(|| { actix_web::App::new().service(web::resource("/").to(|| async { let name = "world".to_owned(); - HelloTemplate { name: &name }.to_response().await + HelloTemplate { name: &name }.to_response() })) }); diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index 56c82aa..1d8d32b 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -201,14 +201,15 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { // Implement Actix-web's `Responder`. fn impl_actix_web_responder(&mut self, buf: &mut Buffer) -> Result<(), CompileError> { self.write_header(buf, "::actix_web::Responder", None)?; - buf.writeln("type Body = actix_web::body::BoxBody;")?; + buf.writeln("type Future = ::askama_actix::futures::Ready<::std::result::Result<::actix_web::HttpResponse, Self::Error>>;")?; + buf.writeln("type Error = ::actix_web::Error;")?; buf.writeln( "fn respond_to(self, _req: &::actix_web::HttpRequest) \ - -> ::actix_web::HttpResponse {", + -> Self::Future {", )?; buf.writeln("use ::askama_actix::TemplateToResponse;")?; - buf.writeln("self.to_response()")?; + buf.writeln("::askama_actix::futures::ready(self.to_response())")?; buf.writeln("}")?; buf.writeln("}") -- cgit