pub struct UpdateStreamBuilder(/* private fields */);Expand description
Configures a long-polling UpdateStream.
Implementations§
Source§impl UpdateStreamBuilder
impl UpdateStreamBuilder
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Sets the long polling timeout. Defaults to 10 seconds.
Sourcepub fn limit(self, limit: u8) -> Self
pub fn limit(self, limit: u8) -> Self
Sets how many updates to retrieve per request. Panics outside 1..=100.
Sourcepub fn allowed_updates(self, allowed: Vec<AllowedUpdate>) -> Self
pub fn allowed_updates(self, allowed: Vec<AllowedUpdate>) -> Self
Selects the update types to receive.
Sourcepub fn drop_pending_updates(self) -> Self
pub fn drop_pending_updates(self) -> Self
Drops pending updates on startup.
Sourcepub async fn build(self) -> UpdateStream
pub async fn build(self) -> UpdateStream
Removes any configured webhook (logging errors) and starts polling.
Examples found in repository?
examples/update_stream.rs (line 8)
5async fn main() -> std::io::Result<()> {
6 pretty_env_logger::init();
7 let bot = Bot::from_env();
8 let mut updates = bot.update_stream().build().await;
9 let mut ctrl_c = std::pin::pin!(tokio::signal::ctrl_c());
10 let mut stopping = false;
11
12 loop {
13 tokio::select! {
14 item = updates.next() => match item {
15 Some(Ok(update)) => {
16 if let UpdateKind::Message(message) = update.kind {
17 if let Some(text) = message.text() {
18 bot.send_message(text).chat_id(message.chat.id).await.log_on_error().await;
19 }
20 }
21 }
22 Some(Err(error)) => log::error!("Could not receive update: {error}"),
23 None => break,
24 },
25 signal = &mut ctrl_c, if !stopping => {
26 signal?;
27 updates.shutdown();
28 stopping = true;
29 }
30 }
31 }
32
33 Ok(())
34}Auto Trait Implementations§
impl !RefUnwindSafe for UpdateStreamBuilder
impl !Sync for UpdateStreamBuilder
impl !UnwindSafe for UpdateStreamBuilder
impl Forget for UpdateStreamBuilder
impl Freeze for UpdateStreamBuilderwhere
*const ArcInner<str> is !null: Freeze,
PhantomData<ArcInner<str>>: Freeze,
*const ArcInner<Url> is !null: Freeze,
PhantomData<ArcInner<Url>>: Freeze,
*const ArcInner<ClientRef> is !null: Freeze,
PhantomData<ArcInner<ClientRef>>: Freeze,
*const u8 is !null: Freeze,
PhantomData<AllowedUpdate>: Freeze,
*const dyn Fn(u32) -> Duration + Send is !null: Freeze,
PhantomData<dyn Fn(u32) -> Duration + Send>: Freeze,
impl Move for UpdateStreamBuilder
impl Send for UpdateStreamBuilder
impl Unpin for UpdateStreamBuilder
impl UnsafeUnpin for UpdateStreamBuilderwhere
*const ArcInner<str> is !null: UnsafeUnpin,
PhantomData<ArcInner<str>>: UnsafeUnpin,
*const ArcInner<Url> is !null: UnsafeUnpin,
PhantomData<ArcInner<Url>>: UnsafeUnpin,
*const ArcInner<ClientRef> is !null: UnsafeUnpin,
PhantomData<ArcInner<ClientRef>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<AllowedUpdate>: UnsafeUnpin,
*const dyn Fn(u32) -> Duration + Send is !null: UnsafeUnpin,
PhantomData<dyn Fn(u32) -> Duration + Send>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Erasable for T
impl<T> Erasable for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more