From c8f197bf58f198e1cb70d6ea3ae49fc51434b718 Mon Sep 17 00:00:00 2001 From: Keuin Date: Mon, 28 Mar 2022 10:17:22 +0800 Subject: Replace Arc with DbPool::clone. --- src/main.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 86f1428..e0cc8cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,7 @@ use std::collections::HashMap; use std::convert::Infallible; use std::net::SocketAddr; -use std::ops::Deref; use std::str::FromStr; -use std::sync::Arc; use teloxide::prelude2::*; use tracing::{debug, info, Level}; @@ -60,9 +58,8 @@ async fn main() { let db = config.db_file.as_str(); info!(db, "Opening database..."); - // TODO replace Arc with DbPool::clone - let db: Arc = Arc::new(database::open(db) - .await.expect(&*format!("cannot open database {}", db))); + let db: DbPool = database::open(db) + .await.expect(&*format!("cannot open database {}", db)); info!("Spawning bot coroutine..."); let bot = Bot::new(config.bot_token); @@ -72,12 +69,12 @@ async fn main() { let route_post = warp::post() .and(warp::body::content_length_limit(MAX_BODY_LENGTH)) .and(warp::body::json()) - .and(with_db(db.deref().clone())) + .and(with_db(db.clone())) .and(with_bot(bot.clone())) .and_then(web::handler); let route_get = warp::get() .and(warp::query::>()) - .and(with_db(db.deref().clone())) + .and(with_db(db.clone())) .and(with_bot(bot.clone())) .and_then(web::get_handler); let routes = warp::path("message") @@ -94,5 +91,5 @@ async fn main() { // gracefully shutdown the database connection info!("Closing database..."); - db.deref().close().await; + db.close().await; } -- cgit v1.2.3