diff options
author | Santo Cariotti <santo@dcariotti.me> | 2022-08-22 16:40:29 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2022-08-22 16:40:29 +0200 |
commit | dd9affd2b247b5df4042b975f8c7cfab59e26c75 (patch) | |
tree | 616950bde5145029b9efb714aba03e5ae616a0a7 | |
parent | 1c217c7fbb0a0cb9e6fad5c1c85fdcb46081e4ed (diff) |
Fix `get_client()` for use `match-case` only once
-rw-r--r-- | server/src/db.rs | 7 | ||||
-rw-r--r-- | server/src/main.rs | 7 |
2 files changed, 6 insertions, 8 deletions
diff --git a/server/src/db.rs b/server/src/db.rs index 8cc4d1f..b08c38c 100644 --- a/server/src/db.rs +++ b/server/src/db.rs @@ -15,6 +15,9 @@ pub async fn setup() -> Result<(), AppError> { Ok(()) } -pub unsafe fn get_client() -> Option<&'static PgPool> { - CONNECTION.as_ref() +pub unsafe fn get_client() -> &'static PgPool { + match &CONNECTION { + Some(client) => &client, + None => panic!("Connection not established!"), + } } diff --git a/server/src/main.rs b/server/src/main.rs index e061b83..17ac707 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -31,12 +31,7 @@ async fn main() { async fn create_app() -> Router { logger::setup(); let _ = db::setup().await; - let pool = unsafe { - match db::get_client() { - Some(client) => client, - None => panic!("Connection not established!"), - } - }; + let pool = unsafe { db::get_client() }; Router::new() .route("/", get(hej)) |