Struct telexide::client::UpdatesStream[][src]

#[must_use = "streams do nothing unless polled"]
pub struct UpdatesStream { /* fields omitted */ }

The stream of incoming updates, created by long polling the telegram API using their getUpdates endpoint.

In most use-cases, this will be handled for you by the Client and the new updates then dispatched to your eventhandlers.

Example

use futures::StreamExt;
use telexide::{
    api::APIClient,
    client::UpdatesStream
};

#[tokio::main]
async fn main() {

    let mut stream = UpdatesStream::new(
        Arc::new(
            Box::new(
                APIClient::new_default(token)
            )
        )
    );

    while let Some(poll) = stream.next().await {
        match poll {
            Ok(update) => {
                println!("ID of the update received: {}", update.update_id);
            },
            Err(err) => return,
        }
    }
}

Implementations

impl UpdatesStream[src]

pub fn new(api: Arc<Box<dyn API + Send>>) -> Self[src]

creates a new update stream using the provided API

pub fn set_limit(&mut self, limit: usize) -> &mut Self[src]

Sets the maximum amount of updates retrieved in one API call

pub fn set_timout(&mut self, timeout: usize) -> &mut Self[src]

Set the timeout in seconds for long polling. Defaults to 5. Should be positive, short polling should be used for testing purposes only.

pub fn set_allowed_updates(&mut self, allowed: Vec<UpdateType>) -> &mut Self[src]

Set which update types you want to receive

pub fn add_allowed_updates(&mut self, allowed: UpdateType) -> &mut Self[src]

Add an update type to the list of update types you want to receive

pub fn remove_allowed_updates(&mut self, to_remove: &UpdateType) -> &mut Self[src]

Remove an update type from the list of update types you want to receive

Trait Implementations

impl Stream for UpdatesStream[src]

type Item = Result<Update>

Values yielded by the stream.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> StreamExt for T where
    T: Stream + ?Sized

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<S, T, E> TryStream for S where
    S: Stream<Item = Result<T, E>> + ?Sized

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<S> TryStreamExt for S where
    S: TryStream + ?Sized

impl<T> UnsafeAny for T where
    T: Any