aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c950e7a..0549a3f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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()
+ }
+ }
+ )
+}