When creating Polling assert that it's an UpdateListener

Former-commit-id: 08da55f54f
This commit is contained in:
Maybe Waffle 2022-07-04 23:39:04 +04:00
parent 4e5e7a145d
commit f0608da9c3
2 changed files with 18 additions and 4 deletions

View file

@ -126,3 +126,11 @@ pub trait AsUpdateStream<'a, E> {
/// [`Stream`]: AsUpdateStream::Stream /// [`Stream`]: AsUpdateStream::Stream
fn as_stream(&'a mut self) -> Self::Stream; fn as_stream(&'a mut self) -> Self::Stream;
} }
#[inline(always)]
pub(crate) fn assert_update_listener<L, E>(listener: L) -> L
where
L: UpdateListener<E>,
{
listener
}

View file

@ -15,7 +15,7 @@ use futures::{ready, stream::Stream};
use crate::{ use crate::{
dispatching::{ dispatching::{
stop_token::{AsyncStopFlag, AsyncStopToken}, stop_token::{AsyncStopFlag, AsyncStopToken},
update_listeners::{AsUpdateStream, UpdateListener}, update_listeners::{assert_update_listener, AsUpdateStream, UpdateListener},
}, },
requests::{HasPayload, Request, Requester}, requests::{HasPayload, Request, Requester},
types::{AllowedUpdate, Update}, types::{AllowedUpdate, Update},
@ -97,7 +97,10 @@ where
pub fn build(self) -> Polling<R> { pub fn build(self) -> Polling<R> {
let Self { bot, timeout, limit, allowed_updates, drop_pending_updates } = self; let Self { bot, timeout, limit, allowed_updates, drop_pending_updates } = self;
let (token, flag) = AsyncStopToken::new_pair(); let (token, flag) = AsyncStopToken::new_pair();
Polling { bot, timeout, limit, allowed_updates, drop_pending_updates, flag, token } let polling =
Polling { bot, timeout, limit, allowed_updates, drop_pending_updates, flag, token };
assert_update_listener(polling)
} }
} }
@ -113,7 +116,10 @@ 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() let polling =
Polling::builder(bot).timeout(Duration::from_secs(10)).delete_webhook().await.build();
assert_update_listener(polling)
} }
/// Returns a long polling update listener with some additional options. /// Returns a long polling update listener with some additional options.
@ -132,7 +138,7 @@ where
builder.timeout = timeout; builder.timeout = timeout;
builder.limit = limit; builder.limit = limit;
builder.allowed_updates = allowed_updates; builder.allowed_updates = allowed_updates;
builder.build() assert_update_listener(builder.build())
} }
async fn delete_webhook_if_setup<R>(requester: &R) async fn delete_webhook_if_setup<R>(requester: &R)