summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-03-28 21:28:48 +0800
committerKeuin <[email protected]>2022-03-28 21:28:48 +0800
commit2d3f83cb7f78706c1ba5af966afc5625037ab5ce (patch)
tree002fd5dd44354f2d5afe2b22c1234c276fb7def5
parent46b838656a9cd4725c6b1cc58f5be55097a4ac58 (diff)
Replace `with_db` and `with_bot` with a generic version.
-rw-r--r--src/main.rs18
1 files 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<Extract=(DbPool, ), Error=Infallible> + Clone {
- warp::any().map(move || db_pool.clone())
-}
-
-// TODO replace with generic
-fn with_bot(bot: Bot) -> impl Filter<Extract=(Bot, ), Error=Infallible> + Clone {
- warp::any().map(move || bot.clone())
+fn with_object<T: Clone + Send>(obj: T)
+ -> impl Filter<Extract=(T, ), Error=Infallible> + 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::<HashMap<String, String>>())
- .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);