pub trait RequesterExt: Requester {
// Provided methods
fn cache_me(self) -> CacheMe<Self> ⓘ
where Self: Sized { ... }
fn erase<'a>(self) -> ErasedRequester<'a, Self::Err> ⓘ
where Self: 'a + Sized { ... }
fn trace(self, settings: Settings) -> Trace<Self> ⓘ
where Self: Sized { ... }
fn throttle(self, limits: Limits) -> Throttle<Self> ⓘ
where Self: Sized + Clone + Send + Sync + 'static,
Self::Err: AsResponseParameters,
Self::GetChat: Send { ... }
fn parse_mode(self, parse_mode: ParseMode) -> DefaultParseMode<Self> ⓘ
where Self: Sized { ... }
}Expand description
Extensions methods for Requester.
Provided Methods§
Sourcefn cache_me(self) -> CacheMe<Self> ⓘwhere
Self: Sized,
Available on crate feature cache_me only.
fn cache_me(self) -> CacheMe<Self> ⓘwhere
Self: Sized,
cache_me only.Add get_me caching ability, see CacheMe for more.
Sourcefn erase<'a>(self) -> ErasedRequester<'a, Self::Err> ⓘwhere
Self: 'a + Sized,
Available on crate feature erased only.
fn erase<'a>(self) -> ErasedRequester<'a, Self::Err> ⓘwhere
Self: 'a + Sized,
erased only.Erase requester type.
Examples found in repository?
examples/erased.rs (line 32)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7 pretty_env_logger::init();
8
9 let chat_id =
10 ChatId(std::env::var("CHAT_ID").expect("Expected CHAT_ID env var").parse::<i64>()?);
11
12 let trace_settings = match std::env::var("TRACE").as_deref() {
13 Ok("EVERYTHING_VERBOSE") => trace::Settings::TRACE_EVERYTHING_VERBOSE,
14 Ok("EVERYTHING") => trace::Settings::TRACE_EVERYTHING,
15 Ok("REQUESTS_VERBOSE") => trace::Settings::TRACE_REQUESTS_VERBOSE,
16 Ok("REQUESTS") => trace::Settings::TRACE_REQUESTS,
17 Ok("RESPONSES_VERBOSE") => trace::Settings::TRACE_RESPONSES_VERBOSE,
18 Ok("RESPONSES") => trace::Settings::TRACE_RESPONSES,
19 Ok("EMPTY") | Ok("") | Err(VarError::NotPresent) => trace::Settings::empty(),
20 Ok(_) | Err(VarError::NotUnicode(_)) => {
21 panic!(
22 "Expected `TRACE` environment variable to be equal to any of the following: \
23 `EVERYTHING_VERBOSE`, `EVERYTHING`, `REQUESTS_VERBOSE`, `REQUESTS`, \
24 `RESPONSES_VERBOSE`, `RESPONSES`, `EMPTY`, `` (empty string)"
25 )
26 }
27 };
28
29 log::info!("Trace settings: {trace_settings:?}");
30
31 let bot = if trace_settings.is_empty() {
32 Bot::from_env().erase()
33 } else {
34 Bot::from_env().trace(trace_settings).erase()
35 };
36
37 bot.send_chat_action(chat_id, ChatAction::Typing).await?;
38 tokio::time::sleep(Duration::from_secs(1)).await;
39 bot.send_message(chat_id, "Hey hey hey").await?;
40
41 Ok(())
42}Sourcefn trace(self, settings: Settings) -> Trace<Self> ⓘwhere
Self: Sized,
Available on crate feature trace_adaptor only.
fn trace(self, settings: Settings) -> Trace<Self> ⓘwhere
Self: Sized,
trace_adaptor only.Trace requests, see Trace for more.
Examples found in repository?
examples/erased.rs (line 34)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7 pretty_env_logger::init();
8
9 let chat_id =
10 ChatId(std::env::var("CHAT_ID").expect("Expected CHAT_ID env var").parse::<i64>()?);
11
12 let trace_settings = match std::env::var("TRACE").as_deref() {
13 Ok("EVERYTHING_VERBOSE") => trace::Settings::TRACE_EVERYTHING_VERBOSE,
14 Ok("EVERYTHING") => trace::Settings::TRACE_EVERYTHING,
15 Ok("REQUESTS_VERBOSE") => trace::Settings::TRACE_REQUESTS_VERBOSE,
16 Ok("REQUESTS") => trace::Settings::TRACE_REQUESTS,
17 Ok("RESPONSES_VERBOSE") => trace::Settings::TRACE_RESPONSES_VERBOSE,
18 Ok("RESPONSES") => trace::Settings::TRACE_RESPONSES,
19 Ok("EMPTY") | Ok("") | Err(VarError::NotPresent) => trace::Settings::empty(),
20 Ok(_) | Err(VarError::NotUnicode(_)) => {
21 panic!(
22 "Expected `TRACE` environment variable to be equal to any of the following: \
23 `EVERYTHING_VERBOSE`, `EVERYTHING`, `REQUESTS_VERBOSE`, `REQUESTS`, \
24 `RESPONSES_VERBOSE`, `RESPONSES`, `EMPTY`, `` (empty string)"
25 )
26 }
27 };
28
29 log::info!("Trace settings: {trace_settings:?}");
30
31 let bot = if trace_settings.is_empty() {
32 Bot::from_env().erase()
33 } else {
34 Bot::from_env().trace(trace_settings).erase()
35 };
36
37 bot.send_chat_action(chat_id, ChatAction::Typing).await?;
38 tokio::time::sleep(Duration::from_secs(1)).await;
39 bot.send_message(chat_id, "Hey hey hey").await?;
40
41 Ok(())
42}Sourcefn throttle(self, limits: Limits) -> Throttle<Self> ⓘ
Available on crate feature throttle only.
fn throttle(self, limits: Limits) -> Throttle<Self> ⓘ
throttle only.Add throttling ability, see Throttle for more.
Note: this spawns the worker, just as Throttle::new_spawn.
Sourcefn parse_mode(self, parse_mode: ParseMode) -> DefaultParseMode<Self> ⓘwhere
Self: Sized,
fn parse_mode(self, parse_mode: ParseMode) -> DefaultParseMode<Self> ⓘwhere
Self: Sized,
Specifies default ParseMode, which will be used during all calls to:
Examples found in repository?
examples/self_info.rs (line 13)
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8 pretty_env_logger::init();
9
10 let chat_id =
11 ChatId(std::env::var("CHAT_ID").expect("Expected CHAT_ID env var").parse::<i64>()?);
12
13 let bot = Bot::from_env().parse_mode(ParseMode::MarkdownV2);
14
15 let Me { user: me, .. } = bot.get_me().await?;
16
17 bot.send_dice(chat_id).emoji(DiceEmoji::Dice).await?;
18 bot.send_message(chat_id, format!("Hi, my name is **{}** 👋", me.first_name)).await?;
19
20 Ok(())
21}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.