Trait teloxide::requests::Request[][src]

pub trait Request: HasPayload {
    type Err: Error + Send;
    type Send: Future + Send;
    type SendRef: Future + Send;
    pub fn send(self) -> Self::Send;
pub fn send_ref(&self) -> Self::SendRef; }

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.

Associated Types

type Err: Error + Send[src]

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

type Send: Future + Send[src]

The type of the future returned by the send method.

type SendRef: Future + Send[src]

A type of the future returned by the send_ref method.

Loading content...

Required methods

pub fn send(self) -> Self::Send[src]

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 _: Me = request.send().await.unwrap();

pub fn send_ref(&self) -> Self::SendRef[src]

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, Bot};

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

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

Implementors

impl<P> Request for JsonRequest<P> where
    P: 'static + Payload + Serialize,
    <P as Payload>::Output: DeserializeOwned
[src]

type Err = RequestError

type Send = Send<P>

type SendRef = SendRef<P>

impl<P> Request for MultipartRequest<P> where
    P: 'static + Payload + MultipartPayload + Serialize,
    <P as Payload>::Output: DeserializeOwned
[src]

type Err = RequestError

type Send = Send<P>

type SendRef = SendRef<P>

impl<R> Request for AutoRequest<R> where
    R: Request
[src]

type Err = <R as Request>::Err

type Send = <R as Request>::Send

type SendRef = <R as Request>::SendRef

impl<R> Request for CachedMeRequest<R> where
    R: Request<Payload = GetMe>, 
[src]

type Err = <R as Request>::Err

type Send = Send<R>

type SendRef = SendRef<R>

impl<R> Request for ThrottlingRequest<R> where
    R: Request + Send
[src]

type Err = <R as Request>::Err

type Send = ThrottlingSend<R>

type SendRef = ThrottlingSendRef<R>

Loading content...