aboutsummaryrefslogtreecommitdiffstats
path: root/askama_actix
diff options
context:
space:
mode:
Diffstat (limited to 'askama_actix')
-rw-r--r--askama_actix/Cargo.toml7
-rw-r--r--askama_actix/src/lib.rs15
-rw-r--r--askama_actix/tests/basic.rs7
3 files changed, 15 insertions, 14 deletions
diff --git a/askama_actix/Cargo.toml b/askama_actix/Cargo.toml
index 253fbd0..8514a9b 100644
--- a/askama_actix/Cargo.toml
+++ b/askama_actix/Cargo.toml
@@ -14,10 +14,11 @@ readme = "README.md"
edition = "2018"
[dependencies]
-actix-web = { version = "3", default-features = false }
+actix-web = { version = "4.0.0-beta.10", default-features = false }
askama = { version = "0.11.0-beta.1", path = "../askama", default-features = false, features = ["with-actix-web", "mime", "mime_guess"] }
-bytes = { version = "0.5" }
+bytes = { version = "1" }
futures-util = { version = "0.3" }
[dev-dependencies]
-actix-rt = { version = "1", default-features = false }
+actix-rt = { version = "2", default-features = false }
+actix-test = "0.1.0-beta.5"
diff --git a/askama_actix/src/lib.rs b/askama_actix/src/lib.rs
index bb58174..2496d92 100644
--- a/askama_actix/src/lib.rs
+++ b/askama_actix/src/lib.rs
@@ -3,23 +3,24 @@
pub use askama::*;
use bytes::BytesMut;
-use actix_web::{error::ErrorInternalServerError, Error, HttpResponse};
+use actix_web::{error::ErrorInternalServerError, HttpResponse};
pub trait TemplateToResponse {
- fn to_response(&self) -> ::std::result::Result<HttpResponse, Error>;
+ fn to_response(&self) -> HttpResponse;
}
impl<T: askama::Template> TemplateToResponse for T {
- fn to_response(&self) -> ::std::result::Result<HttpResponse, Error> {
+ fn to_response(&self) -> HttpResponse {
let mut buffer = BytesMut::with_capacity(self.size_hint());
- self.render_into(&mut buffer)
- .map_err(|_| ErrorInternalServerError("Template parsing error"))?;
+ if self.render_into(&mut buffer).is_err() {
+ return ErrorInternalServerError("Template parsing error").error_response();
+ }
let ctype =
askama::mime::extension_to_mime_type(self.extension().unwrap_or("txt")).to_string();
- Ok(HttpResponse::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 125270f..070cbf6 100644
--- a/askama_actix/tests/basic.rs
+++ b/askama_actix/tests/basic.rs
@@ -1,5 +1,4 @@
use actix_web::http::header::CONTENT_TYPE;
-use actix_web::test;
use actix_web::web;
use askama_actix::{Template, TemplateToResponse};
use bytes::Bytes;
@@ -12,7 +11,7 @@ struct HelloTemplate<'a> {
#[actix_rt::test]
async fn test_actix_web() {
- let srv = test::start(|| {
+ let srv = actix_test::start(|| {
actix_web::App::new()
.service(web::resource("/").to(|| async { HelloTemplate { name: "world" } }))
});
@@ -31,10 +30,10 @@ async fn test_actix_web() {
#[actix_rt::test]
async fn test_actix_web_responder() {
- let srv = test::start(|| {
+ let srv = actix_test::start(|| {
actix_web::App::new().service(web::resource("/").to(|| async {
let name = "world".to_owned();
- HelloTemplate { name: &name }.to_response()
+ HelloTemplate { name: &name }.to_response().await
}))
});