From c6f9a053c7328e6c782508114bd96aa569b5de7d Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 28 Jan 2020 22:06:11 +0100 Subject: Move Rocket integration into askama_rocket crate --- askama_rocket/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 askama_rocket/src/lib.rs (limited to 'askama_rocket/src') diff --git a/askama_rocket/src/lib.rs b/askama_rocket/src/lib.rs new file mode 100644 index 0000000..6db3b7b --- /dev/null +++ b/askama_rocket/src/lib.rs @@ -0,0 +1,16 @@ +use std::io::Cursor; + +pub use askama::*; +use rocket::http::{ContentType, Status}; +pub use rocket::request::Request; +use rocket::response::Response; +pub use rocket::response::{Responder, Result}; + +pub fn respond(t: &T, ext: &str) -> Result<'static> { + let rsp = t.render().map_err(|_| Status::InternalServerError)?; + let ctype = ContentType::from_extension(ext).ok_or(Status::InternalServerError)?; + Response::build() + .header(ctype) + .sized_body(Cursor::new(rsp)) + .ok() +} -- cgit