logo
pub trait Requestwhere
    Self: HasPayload,
    Self: IntoFuture<Output = Result<Output<Self>, Self::Err>, IntoFuture = Self::Send>,
{ type Err: Error + Send; type Send: Future<Output = Result<Output<Self>, Self::Err>> + Send; type SendRef: Future<Output = Result<Output<Self>, Self::Err>> + Send; fn send(self) -> Self::Send; fn send_ref(&self) -> Self::SendRef; fn erase<'a>(self) -> ErasedRequest<'a, Self::Payload, Self::Err>Notable traits for ErasedRequest<'a, T, E>impl<'a, T, E> Request for ErasedRequest<'a, T, E>where
    T: Payload,
    E: Error + Send,
type Err = E; type Send = BoxFuture<'a, Result<Output<Self>, Self::Err>>; type SendRef = BoxFuture<'a, Result<Output<Self>, Self::Err>>;

    where
        Self: Sized + 'a
, { ... } }
Expand description

A ready-to-send Telegram request.

Implementation notes

It is not recommended to do any kind of work in send or send_ref. Instead it’s recommended to do all the (possible) stuff in the returned future. In other words — keep it lazy.

This is crucial for request wrappers which may want to cancel and/or never send the underlying request. E.g.: Throttle<B>’s send_ref calls B::send_ref while not meaning to really send the request at the moment.

Required Associated Types

The type of an error that may happen while sending a request to Telegram.

The type of the future returned by the send method.

A type of the future returned by the send_ref method.

Required Methods

Send this request.

Examples
use teloxide_core::{
    payloads::GetMe,
    requests::{JsonRequest, Request},
    types::Me,
    Bot,
};

let bot = Bot::new("TOKEN");

// Note: it's recommended to `Requester` instead of creating requests directly
let method = GetMe::new();
let request = JsonRequest::new(bot, method);
let request_clone = request.clone();
let _: Me = request.send().await.unwrap();

// You can also just await requests, without calling `send`:
let _: Me = request_clone.await.unwrap();

Send this request by reference.

This method is analogous to send, but it doesn’t take the ownership of self. This allows to send the same (or slightly different) requests over and over.

Also, it is expected that calling this method is better than just cloning requests. (Because instead of copying all the data and then serializing it, this method should just serialize the data.)

Examples
use teloxide_core::{prelude::*, requests::Request, types::ChatId, Bot};

let bot = Bot::new("TOKEN");

let mut req = bot.send_message(ChatId(0xAAAAAAAA), "Hi there!");
for chat_id in chat_ids {
    req.chat_id = chat_id;
    req.send_ref().await.unwrap();
}

Provided Methods

Available on crate feature erased only.

Implementors