teloxide_core/requests/requester_ext.rs
1use crate::{adaptors::DefaultParseMode, requests::Requester, types::ParseMode};
2
3#[cfg(feature = "cache_me")]
4use crate::adaptors::CacheMe;
5
6#[cfg(feature = "erased")]
7use crate::adaptors::ErasedRequester;
8
9#[cfg(feature = "trace_adaptor")]
10use crate::adaptors::trace::{Settings, Trace};
11
12#[cfg(feature = "throttle")]
13use crate::adaptors::throttle::{Limits, Throttle};
14
15/// Extensions methods for [`Requester`].
16pub trait RequesterExt: Requester {
17 /// Add `get_me` caching ability, see [`CacheMe`] for more.
18 #[cfg(feature = "cache_me")]
19 #[must_use]
20 fn cache_me(self) -> CacheMe<Self>
21 where
22 Self: Sized,
23 {
24 CacheMe::new(self)
25 }
26
27 /// Erase requester type.
28 #[cfg(feature = "erased")]
29 #[must_use]
30 fn erase<'a>(self) -> ErasedRequester<'a, Self::Err>
31 where
32 Self: 'a,
33 Self: Sized,
34 {
35 ErasedRequester::new(self)
36 }
37
38 /// Trace requests, see [`Trace`] for more.
39 #[cfg(feature = "trace_adaptor")]
40 #[must_use]
41 fn trace(self, settings: Settings) -> Trace<Self>
42 where
43 Self: Sized,
44 {
45 Trace::new(self, settings)
46 }
47
48 /// Add throttling ability, see [`Throttle`] for more.
49 ///
50 /// Note: this spawns the worker, just as [`Throttle::new_spawn`].
51 #[cfg(feature = "throttle")]
52 #[must_use]
53 fn throttle(self, limits: Limits) -> Throttle<Self>
54 where
55 Self: Sized + Clone + Send + Sync + 'static,
56 Self::Err: crate::errors::AsResponseParameters,
57 Self::GetChat: Send,
58 {
59 Throttle::new_spawn(self, limits)
60 }
61
62 /// Specifies default [`ParseMode`], which will be used during all calls to:
63 ///
64 /// - [`send_message`]
65 /// - [`send_photo`]
66 /// - [`send_video`]
67 /// - [`send_audio`]
68 /// - [`send_document`]
69 /// - [`send_animation`]
70 /// - [`send_voice`]
71 /// - [`send_poll`]
72 /// - [`edit_message_text`] (and [`edit_message_text_inline`])
73 /// - [`edit_message_caption`] (and [`edit_message_caption_inline`])
74 ///
75 /// [`send_message`]: crate::requests::Requester::send_message
76 /// [`send_photo`]: crate::requests::Requester::send_photo
77 /// [`send_video`]: crate::requests::Requester::send_video
78 /// [`send_audio`]: crate::requests::Requester::send_audio
79 /// [`send_document`]: crate::requests::Requester::send_document
80 /// [`send_animation`]: crate::requests::Requester::send_animation
81 /// [`send_voice`]: crate::requests::Requester::send_voice
82 /// [`send_poll`]: crate::requests::Requester::send_poll
83 /// [`edit_message_text`]: crate::requests::Requester::edit_message_text
84 /// [`edit_message_text_inline`]:
85 /// crate::requests::Requester::edit_message_text_inline
86 /// [`edit_message_caption`]:
87 /// crate::requests::Requester::edit_message_caption
88 /// [`edit_message_caption_inline`]:
89 /// crate::requests::Requester::edit_message_caption_inline
90 #[must_use]
91 fn parse_mode(self, parse_mode: ParseMode) -> DefaultParseMode<Self>
92 where
93 Self: Sized,
94 {
95 DefaultParseMode::new(self, parse_mode)
96 }
97}
98
99impl<T> RequesterExt for T
100where
101 T: Requester,
102{
103 /* use default impls */
104}