Trait teloxide::requests::Request [−][src]
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.
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(); }
Implementors
impl<P> Request for JsonRequest<P> where
P: 'static + Payload + Serialize,
<P as Payload>::Output: DeserializeOwned,
[src]
P: 'static + Payload + Serialize,
<P as Payload>::Output: DeserializeOwned,
type Err = RequestError
type Send = Send<P>
type SendRef = SendRef<P>
pub fn send(self) -> <JsonRequest<P> as Request>::Send
[src]
pub fn send_ref(&self) -> <JsonRequest<P> as Request>::SendRef
[src]
impl<P> Request for MultipartRequest<P> where
P: 'static + Payload + MultipartPayload + Serialize,
<P as Payload>::Output: DeserializeOwned,
[src]
P: 'static + Payload + MultipartPayload + Serialize,
<P as Payload>::Output: DeserializeOwned,
type Err = RequestError
type Send = Send<P>
type SendRef = SendRef<P>
pub fn send(self) -> <MultipartRequest<P> as Request>::Send
[src]
pub fn send_ref(&self) -> <MultipartRequest<P> as Request>::SendRef
[src]
impl<R> Request for AutoRequest<R> where
R: Request,
[src]
R: Request,
type Err = <R as Request>::Err
type Send = <R as Request>::Send
type SendRef = <R as Request>::SendRef
pub fn send(self) -> <AutoRequest<R> as Request>::SendⓘNotable traits for AutoRequest<R>
impl<R> Future for AutoRequest<R> where
R: Request, type Output = Result<<<R as HasPayload>::Payload as Payload>::Output, <R as Request>::Err>;
[src]
Notable traits for AutoRequest<R>
impl<R> Future for AutoRequest<R> where
R: Request, type Output = Result<<<R as HasPayload>::Payload as Payload>::Output, <R as Request>::Err>;
pub fn send_ref(&self) -> <AutoRequest<R> as Request>::SendRefⓘNotable traits for AutoRequest<R>
impl<R> Future for AutoRequest<R> where
R: Request, type Output = Result<<<R as HasPayload>::Payload as Payload>::Output, <R as Request>::Err>;
[src]
Notable traits for AutoRequest<R>
impl<R> Future for AutoRequest<R> where
R: Request, type Output = Result<<<R as HasPayload>::Payload as Payload>::Output, <R as Request>::Err>;
impl<R> Request for CachedMeRequest<R> where
R: Request<Payload = GetMe>,
[src]
R: Request<Payload = GetMe>,
type Err = <R as Request>::Err
type Send = Send<R>
type SendRef = SendRef<R>
pub fn send(self) -> <CachedMeRequest<R> as Request>::Send
[src]
pub fn send_ref(&self) -> <CachedMeRequest<R> as Request>::SendRef
[src]
impl<R> Request for ThrottlingRequest<R> where
R: Request + Send,
[src]
R: Request + Send,