Move polling_builder => Polling::builder

This commit is contained in:
Maybe Waffle 2022-06-27 03:28:23 +04:00
parent 195d34ba0c
commit 79f6cf4ee9
3 changed files with 22 additions and 20 deletions

View file

@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Security checks based on `secret_token` param of `set_webhook` to built-in webhooks - Security checks based on `secret_token` param of `set_webhook` to built-in webhooks
- `dispatching::update_listeners::{polling_builder, PollingBuilder, Polling, PollingStream}` - `dispatching::update_listeners::{PollingBuilder, Polling, PollingStream}`
### Fixed ### Fixed

View file

@ -44,7 +44,7 @@ mod stateful_listener;
#[allow(deprecated)] #[allow(deprecated)]
pub use self::{ pub use self::{
polling::{polling, polling_builder, polling_default, Polling, PollingBuilder, PollingStream}, polling::{polling, polling_default, Polling, PollingBuilder, PollingStream},
stateful_listener::StatefulListener, stateful_listener::StatefulListener,
}; };

View file

@ -99,21 +99,6 @@ where
} }
} }
/// Returns a builder for polling update listener.
pub fn polling_builder<R>(bot: R) -> PollingBuilder<R>
where
R: Requester + Send + 'static,
<R as Requester>::GetUpdates: Send,
{
PollingBuilder {
bot,
timeout: None,
limit: None,
allowed_updates: None,
drop_pending_updates: false,
}
}
/// Returns a long polling update listener with `timeout` of 10 seconds. /// Returns a long polling update listener with `timeout` of 10 seconds.
/// ///
/// See also: [`polling_builder`]. /// See also: [`polling_builder`].
@ -126,11 +111,11 @@ where
R: Requester + Send + 'static, R: Requester + Send + 'static,
<R as Requester>::GetUpdates: Send, <R as Requester>::GetUpdates: Send,
{ {
polling_builder(bot).timeout(Duration::from_secs(10)).delete_webhook().await.build() Polling::builder(bot).timeout(Duration::from_secs(10)).delete_webhook().await.build()
} }
/// Returns a long polling update listener with some additional options. /// Returns a long polling update listener with some additional options.
#[deprecated(since = "0.10.0", note = "use `polling_builder` instead")] #[deprecated(since = "0.10.0", note = "use `Polling::builder()` instead")]
pub fn polling<R>( pub fn polling<R>(
bot: R, bot: R,
timeout: Option<Duration>, timeout: Option<Duration>,
@ -141,7 +126,7 @@ where
R: Requester + Send + 'static, R: Requester + Send + 'static,
<R as Requester>::GetUpdates: Send, <R as Requester>::GetUpdates: Send,
{ {
let mut builder = polling_builder(bot); let mut builder = Polling::builder(bot);
builder.timeout = timeout; builder.timeout = timeout;
builder.limit = limit; builder.limit = limit;
builder.allowed_updates = allowed_updates; builder.allowed_updates = allowed_updates;
@ -250,6 +235,23 @@ pub struct Polling<B: Requester> {
token: AsyncStopToken, token: AsyncStopToken,
} }
impl<R> Polling<R>
where
R: Requester + Send + 'static,
<R as Requester>::GetUpdates: Send,
{
/// Returns a builder for polling update listener.
pub fn builder(bot: R) -> PollingBuilder<R> {
PollingBuilder {
bot,
timeout: None,
limit: None,
allowed_updates: None,
drop_pending_updates: false,
}
}
}
#[pin_project::pin_project] #[pin_project::pin_project]
pub struct PollingStream<'a, B: Requester> { pub struct PollingStream<'a, B: Requester> {
/// Parent structure /// Parent structure