From a8503e0fa2d6065b1c471becf76dde68571b7984 Mon Sep 17 00:00:00 2001 From: Sergey Pashinin Date: Thu, 11 Nov 2021 12:55:09 +0300 Subject: Prepare for actix-web v4 (#553) --- askama_actix/src/lib.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'askama_actix/src/lib.rs') 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; + fn to_response(&self) -> HttpResponse; } impl TemplateToResponse for T { - fn to_response(&self) -> ::std::result::Result { + 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()) } } -- cgit