From c378d6ef4e524da96718beec6f989e8ac51d1531 Mon Sep 17 00:00:00 2001 From: Waffle Date: Fri, 25 Jun 2021 17:24:31 +0300 Subject: [PATCH] Make `StatefulListener::new` a little more convinient Remove `timeout_hint` from the `StatefulListener::new` function. This parameter is confusing and is likely to be set to `None` in most cases. Add a `StatefulListener::new_with_timeout_hint` parameter which is the same as the old `StatefulListener::new`. --- examples/heroku_ping_pong_bot/src/main.rs | 2 +- examples/ngrok_ping_pong_bot/src/main.rs | 2 +- .../update_listeners/stateful_listener.rs | 14 +++++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/examples/heroku_ping_pong_bot/src/main.rs b/examples/heroku_ping_pong_bot/src/main.rs index ddb7769f..2043ec49 100644 --- a/examples/heroku_ping_pong_bot/src/main.rs +++ b/examples/heroku_ping_pong_bot/src/main.rs @@ -62,7 +62,7 @@ pub async fn webhook(bot: AutoSend) -> impl update_listeners::UpdateListene fn streamf(state: &mut (S, T)) -> &mut S { &mut state.0 } - StatefulListener::new((stream, stop_token), streamf, |state: &mut (_, AsyncStopToken)| state.1.clone(), None:: fn(&'a _) -> _>) + StatefulListener::new((stream, stop_token), streamf, |state: &mut (_, AsyncStopToken)| state.1.clone()) } async fn run() { diff --git a/examples/ngrok_ping_pong_bot/src/main.rs b/examples/ngrok_ping_pong_bot/src/main.rs index 8863eb8f..8a35d5ad 100644 --- a/examples/ngrok_ping_pong_bot/src/main.rs +++ b/examples/ngrok_ping_pong_bot/src/main.rs @@ -54,7 +54,7 @@ pub async fn webhook(bot: AutoSend) -> impl update_listeners::UpdateListene fn streamf(state: &mut (S, T)) -> &mut S { &mut state.0 } - StatefulListener::new((stream, stop_token), streamf, |state: &mut (_, AsyncStopToken)| state.1.clone(), None:: fn(&'a _) -> _>) + StatefulListener::new((stream, stop_token), streamf, |state: &mut (_, AsyncStopToken)| state.1.clone()) } async fn run() { diff --git a/src/dispatching/update_listeners/stateful_listener.rs b/src/dispatching/update_listeners/stateful_listener.rs index 9150daef..b7a243c6 100644 --- a/src/dispatching/update_listeners/stateful_listener.rs +++ b/src/dispatching/update_listeners/stateful_listener.rs @@ -39,9 +39,21 @@ pub struct StatefulListener { pub timeout_hint: Option, } +impl StatefulListener fn(&'a St) -> Option> { + /// Creates new stateful listener from it's components. + pub fn new(state: St, stream: Assf, stop_token: Sf) -> Self { + Self { state, stream, stop_token, timeout_hint: None } + } +} + impl StatefulListener { /// Creates new stateful listener from it's components. - pub fn new(state: St, stream: Assf, stop_token: Sf, timeout_hint: Option) -> Self { + pub fn new_with_timeout_hint( + state: St, + stream: Assf, + stop_token: Sf, + timeout_hint: Option, + ) -> Self { Self { state, stream, stop_token, timeout_hint } } }