Trait teloxide_core::requests::Request
source · pub trait Requestwhere
Self: HasPayload + 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;
// Required methods
fn send(self) -> Self::Send;
fn send_ref(&self) -> Self::SendRef;
// Provided method
fn erase<'a>(self) -> ErasedRequest<'a, Self::Payload, 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§
sourcetype Err: Error + Send
type Err: Error + Send
The type of an error that may happen while sending a request to Telegram.
Required Methods§
sourcefn send(self) -> Self::Send
fn send(self) -> Self::Send
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();
sourcefn send_ref(&self) -> Self::SendRef
fn send_ref(&self) -> Self::SendRef
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§
fn erase<'a>(self) -> ErasedRequest<'a, Self::Payload, Self::Err> ⓘwhere
Self: Sized + 'a,
erased
only.Implementors§
source§impl<'a, T, E> Request for ErasedRequest<'a, T, E>
Available on crate feature erased
only.
impl<'a, T, E> Request for ErasedRequest<'a, T, E>
erased
only.source§impl<P> Request for JsonRequest<P>
impl<P> Request for JsonRequest<P>
source§impl<P> Request for MultipartRequest<P>
impl<P> Request for MultipartRequest<P>
source§impl<R> Request for CachedMeRequest<R>
Available on crate feature cache_me
only.
impl<R> Request for CachedMeRequest<R>
cache_me
only.source§impl<R> Request for ThrottlingRequest<R>
Available on crate feature throttle
only.
impl<R> Request for ThrottlingRequest<R>
throttle
only.