From d3c69eb0c920d136b63041586e4b1551d7a15e00 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 25 Sep 2023 20:17:28 +0400 Subject: [PATCH] Remove `UpdateListener::timeout_hint` --- crates/teloxide/src/update_listeners.rs | 15 ---------- .../teloxide/src/update_listeners/polling.rs | 4 --- .../src/update_listeners/stateful_listener.rs | 29 +++++-------------- 3 files changed, 7 insertions(+), 41 deletions(-) diff --git a/crates/teloxide/src/update_listeners.rs b/crates/teloxide/src/update_listeners.rs index 5594d949..6e03ef01 100644 --- a/crates/teloxide/src/update_listeners.rs +++ b/crates/teloxide/src/update_listeners.rs @@ -32,8 +32,6 @@ pub mod webhooks; use futures::Stream; -use std::time::Duration; - use crate::{ stop::StopToken, types::{AllowedUpdate, Update}, @@ -94,19 +92,6 @@ pub trait UpdateListener: fn hint_allowed_updates(&mut self, hint: &mut dyn Iterator) { let _ = hint; } - - /// The timeout duration hint. - /// - /// This hints how often dispatcher should check for a shutdown. E.g., for - /// [`polling()`] this returns the [`timeout`]. - /// - /// [`timeout`]: crate::payloads::GetUpdates::timeout - /// - /// If you are implementing this trait and not sure what to return from this - /// function, just leave it with the default implementation. - fn timeout_hint(&self) -> Option { - None - } } /// [`UpdateListener`]'s supertrait/extension. diff --git a/crates/teloxide/src/update_listeners/polling.rs b/crates/teloxide/src/update_listeners/polling.rs index 23a3c527..f055121a 100644 --- a/crates/teloxide/src/update_listeners/polling.rs +++ b/crates/teloxide/src/update_listeners/polling.rs @@ -301,10 +301,6 @@ impl UpdateListener for Polling { // before self.allowed_updates = Some(hint.collect()); } - - fn timeout_hint(&self) -> Option { - self.timeout - } } impl<'a, B: Requester + Send + 'a> AsUpdateStream<'a> for Polling { diff --git a/crates/teloxide/src/update_listeners/stateful_listener.rs b/crates/teloxide/src/update_listeners/stateful_listener.rs index 2cbca5cf..87ae492a 100644 --- a/crates/teloxide/src/update_listeners/stateful_listener.rs +++ b/crates/teloxide/src/update_listeners/stateful_listener.rs @@ -1,5 +1,3 @@ -use std::time::Duration; - use futures::Stream; use crate::{ @@ -17,7 +15,7 @@ use crate::{ /// /// [`polling`]: crate::update_listeners::polling() #[non_exhaustive] -pub struct StatefulListener { +pub struct StatefulListener { /// The state of the listener. pub state: St, @@ -36,38 +34,30 @@ pub struct StatefulListener { /// Must implement `FnMut(&mut St, &mut dyn Iterator)`. pub hint_allowed_updates: Option, - - /// The function used as [`UpdateListener::timeout_hint`]. - /// - /// Must implement `Fn(&St) -> Option`. - pub timeout_hint: Option, } type Haufn = for<'a, 'b> fn(&'a mut State, &'b mut dyn Iterator); -type Thfn = for<'a> fn(&'a State) -> Option; -impl StatefulListener, Thfn> { +impl StatefulListener> { /// Creates a new stateful listener from its components. pub fn new(state: St, stream: Assf, stop_token: Sf) -> Self { - Self::new_with_hints(state, stream, stop_token, None, None) + Self::new_with_hints(state, stream, stop_token, None) } } -impl StatefulListener { +impl StatefulListener { /// Creates a new stateful listener from its components. pub fn new_with_hints( state: St, stream: Assf, stop_token: Sf, hint_allowed_updates: Option, - timeout_hint: Option, ) -> Self { - Self { state, stream, stop_token, hint_allowed_updates, timeout_hint } + Self { state, stream, stop_token, hint_allowed_updates } } } -impl<'a, St, Assf, Sf, Hauf, Thf, Strm, E> AsUpdateStream<'a> - for StatefulListener +impl<'a, St, Assf, Sf, Hauf, Strm, E> AsUpdateStream<'a> for StatefulListener where (St, Strm): 'a, Strm: Send, @@ -82,12 +72,11 @@ where } } -impl UpdateListener for StatefulListener +impl UpdateListener for StatefulListener where Self: for<'a> AsUpdateStream<'a, StreamErr = E>, Sf: FnMut(&mut St) -> StopToken, Hauf: FnMut(&mut St, &mut dyn Iterator), - Thf: Fn(&St) -> Option, { type Err = E; @@ -100,8 +89,4 @@ where f(&mut self.state, hint); } } - - fn timeout_hint(&self) -> Option { - self.timeout_hint.as_ref().and_then(|f| f(&self.state)) - } }