Created
February 16, 2017 01:03
-
-
Save svenstaro/71d822433fbcdbcee86c7f7354449f30 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
impl<'a, 'r> FromRequest<'a, 'r> for DB { | |
type Error = (); | |
fn from_request(request: &'a Request<'r>) -> request::Outcome<DB, ()> { | |
let pool = match <State<r2d2::Pool> as FromRequest>::from_request(request) { | |
Outcome::Success(pool) => pool, | |
Outcome::Failure(e) => return Outcome::Failure(e), | |
Outcome::Forward(_) => return Outcome::Forward(()), | |
}; | |
match pool.get() { | |
Ok(conn) => Outcome::Success(DB(conn)), | |
Err(_) => Outcome::Failure((Status::ServiceUnavailable, ())) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment