From 2d3f83cb7f78706c1ba5af966afc5625037ab5ce Mon Sep 17 00:00:00 2001 From: Keuin Date: Mon, 28 Mar 2022 21:28:48 +0800 Subject: Replace `with_db` and `with_bot` with a generic version. --- src/main.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index d54a97c..8ada3a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,13 +25,9 @@ mod config; const CONFIG_FILE_NAME: &str = "kimikuri.json"; -fn with_db(db_pool: DbPool) -> impl Filter + Clone { - warp::any().map(move || db_pool.clone()) -} - -// TODO replace with generic -fn with_bot(bot: Bot) -> impl Filter + Clone { - warp::any().map(move || bot.clone()) +fn with_object(obj: T) + -> impl Filter + Clone { + warp::any().map(move || obj.clone()) } #[instrument] @@ -91,13 +87,13 @@ async fn main() { let route_post = warp::post() .and(warp::body::content_length_limit(config.max_body_size)) .and(warp::body::json()) - .and(with_db(db.clone())) - .and(with_bot(bot.clone())) + .and(with_object(db.clone())) + .and(with_object(bot.clone())) .and_then(web::handler); let route_get = warp::get() .and(warp::query::>()) - .and(with_db(db.clone())) - .and(with_bot(bot.clone())) + .and(with_object(db.clone())) + .and(with_object(bot.clone())) .and_then(web::get_handler); let routes = warp::path("message") .and(route_post).or(route_get); -- cgit v1.2.3