aboutsummaryrefslogtreecommitdiffstats
path: root/askama_actix/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar Sergey Pashinin <sergey@pashinin.com>2021-11-11 12:55:09 +0300
committerLibravatar GitHub <noreply@github.com>2021-11-11 10:55:09 +0100
commita8503e0fa2d6065b1c471becf76dde68571b7984 (patch)
treee893f04e6e5e01397ff675a2779515a621acd2a6 /askama_actix/src/lib.rs
parentcfe83bcb73b9e0cfd8a2d3151e4cab38327eabea (diff)
downloadaskama-a8503e0fa2d6065b1c471becf76dde68571b7984.tar.gz
askama-a8503e0fa2d6065b1c471becf76dde68571b7984.tar.bz2
askama-a8503e0fa2d6065b1c471becf76dde68571b7984.zip
Prepare for actix-web v4 (#553)
Diffstat (limited to 'askama_actix/src/lib.rs')
-rw-r--r--askama_actix/src/lib.rs15
1 files changed, 8 insertions, 7 deletions
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())
}
}