Skip to main content

teloxide_core/requests/
payload.rs

1use std::time::Duration;
2
3/// Payload of a request.
4///
5/// Simply speaking, structures implementing this trait represent arguments of
6/// a Telegram bot API method.
7///
8/// Also, this trait provides some additional information needed to send a
9/// request to Telegram.
10#[cfg_attr(all(any(docsrs, dep_docsrs), feature = "nightly"), doc(notable_trait))]
11pub trait Payload {
12    /// The return type of a Telegram method.
13    ///
14    /// Note: it should not include `Result` wrappers (e.g. it should be simply
15    /// [`Message`], [`True`] or something else).
16    ///
17    /// [`Message`]: crate::types::Message
18    /// [`True`]: crate::types::True
19    type Output;
20
21    /// Name of the Rust payload (for example, `EditMessageTextInline`).
22    const NAME: &'static str;
23
24    /// Case-insensitive Telegram method called on the wire (for example,
25    /// `EditMessageText`). Defaults to the payload name.
26    const TELEGRAM_METHOD: &'static str = Self::NAME;
27
28    /// If this payload may take long time to execute (e.g. [`GetUpdates`] with
29    /// big `timeout`), the **minimum** timeout that should be used.
30    ///
31    /// [`GetUpdates`]: crate::payloads::GetUpdates
32    fn timeout_hint(&self) -> Option<Duration> {
33        None
34    }
35}