aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/mod.rs')
-rw-r--r--src/utils/mod.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 5392224..ad6cff1 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -12,10 +12,10 @@ pub fn init_db_pool<'a>(dburl: &'a str) -> Pool {
r2d2::Pool::builder().build(manager).expect("db pool")
}
-use std::ops::Deref;
use rocket::http::Status;
use rocket::request::{self, FlashMessage, FromRequest};
-use rocket::{Request, State, Outcome};
+use rocket::{Outcome, Request, State};
+use std::ops::Deref;
// Connection request guard type: a wrapper around an r2d2 pooled connection.
pub struct DbConn(pub r2d2::PooledConnection<ConnectionManager<PgConnection>>);
@@ -30,7 +30,7 @@ impl<'a, 'r> FromRequest<'a, 'r> for DbConn {
let pool = request.guard::<State<Pool>>()?;
match pool.get() {
Ok(conn) => Outcome::Success(DbConn(conn)),
- Err(_) => Outcome::Failure((Status::ServiceUnavailable, ()))
+ Err(_) => Outcome::Failure((Status::ServiceUnavailable, ())),
}
}
}
@@ -49,7 +49,7 @@ impl Deref for DbConn {
pub struct Page<T: Display> {
pub title: String,
pub flash: Option<FlashMessage>,
- pub content: T
+ pub content: T,
}
macro_rules! implement_responder_for {
@@ -59,14 +59,17 @@ macro_rules! implement_responder_for {
// like this: `$template_type<'a>`
// So it will have to be passed in to the argument at
// the macro incovation instead.
- ($template_type:ty) => (
+ ($template_type:ty) => {
impl<'a> ::rocket::response::Responder<'a> for ::utils::Page<$template_type> {
- fn respond_to(self, _: &::rocket::Request) -> Result<::rocket::Response<'static>, ::rocket::http::Status> {
+ fn respond_to(
+ self,
+ _: &::rocket::Request,
+ ) -> Result<::rocket::Response<'static>, ::rocket::http::Status> {
::rocket::Response::build()
.header(::rocket::http::ContentType::HTML)
.sized_body(::std::io::Cursor::new(format!("{}", &self)))
.ok()
}
}
- )
+ };
}