aboutsummaryrefslogblamecommitdiffstats
path: root/askama_rocket/src/lib.rs
blob: ae683c9546677fbb33e091aad43a8a8fcaa2ae1f (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

                                   












                                                                                     
                                                

             
#![deny(elided_lifetimes_in_paths)]

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: Template>(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(rsp.len(), Cursor::new(rsp))
        .ok()
}