diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -67,3 +67,28 @@ impl Deref for DbConn { &self.0 } } + +#[macro_export] +macro_rules! implement_responder_for { + // Implement a responder for the given template type + // + // Seems I can't add the lifetime after the matcher, + // like this: `$template_type<'a>` + // So it will have to be passed in to the argument at + // the macro incovation instead. + ($template_type:ty) => ( + use rocket::response::{Response, Responder}; + use rocket::http::{ContentType, Status}; + use std::io::Cursor; + use rocket::request::Request; + + impl<'a> Responder<'a> for $template_type { + fn respond_to(self, _: &Request) -> Result<Response<'static>, Status> { + Response::build() + .header(ContentType::HTML) + .sized_body(Cursor::new(format!("{}", &self))) + .ok() + } + } + ) +} |