diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-08-01 14:29:50 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-08-01 19:40:57 +0200 |
commit | b9bce0c426ab258f2c5891ac7eecd944f749e27c (patch) | |
tree | 3981bc54a4b0602d918ea378bc0847ea3a988633 /src/utils | |
parent | d9a217e3b73a702875c2907d7d1811c3dd82d8e9 (diff) | |
download | rocket-blog-b9bce0c426ab258f2c5891ac7eecd944f749e27c.tar.gz rocket-blog-b9bce0c426ab258f2c5891ac7eecd944f749e27c.tar.bz2 rocket-blog-b9bce0c426ab258f2c5891ac7eecd944f749e27c.zip |
Run rustfmt on project.
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/mod.rs | 17 |
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() } } - ) + }; } |