teloxide_core_ng/lib.rs
1//! Core part of the [`teloxide`] library.
2//!
3//! This library provides tools for making requests to the [Telegram Bot API]
4//! (Currently, version `9.1` is supported) with ease. The library is fully
5//! asynchronous and built using [`tokio`].
6//!
7//!```toml
8//! teloxide-core = "0.13.0"
9//! ```
10//! _Compiler support: requires rustc 1.85+_.
11//!
12//! ```
13//! # async {
14//! # let chat_id = teloxide_core_ng::types::ChatId(-1);
15//! use teloxide_core_ng::{
16//! prelude::*,
17//! types::{DiceEmoji, ParseMode},
18//! };
19//!
20//! let bot = Bot::from_env().parse_mode(ParseMode::MarkdownV2);
21//!
22//! let me = bot.get_me().await?;
23//!
24//! bot.send_dice(chat_id).emoji(DiceEmoji::Dice).await?;
25//! bot.send_message(chat_id, format!("Hi, my name is **{}** 👋", me.user.first_name)).await?;
26//! # Ok::<_, Box<dyn std::error::Error>>(()) };
27//! ```
28//!
29//! <div align="center">
30//! <img src=https://user-images.githubusercontent.com/38225716/103929465-6b91e100-512e-11eb-826d-39b096f16548.gif />
31//! </div>
32//!
33//! [`teloxide`]: https://docs.rs/teloxide
34//! [Telegram Bot API]: https://core.telegram.org/bots/api
35//! [`tokio`]: https://tokio.rs
36//!
37//! ## Cargo features
38//!
39//! - `native-tls` = use [`native-tls`] tls implementation (**enabled by
40//! default**)
41//! - `rustls` — use [`rustls`] tls implementation
42//! - `trace_adaptor` — enables [`Trace`] bot adaptor
43//! - `erased` — enables [`ErasedRequester`] bot adaptor
44//! - `throttle` — enables [`Throttle`] bot adaptor
45//! - `cache_me` — enables [`CacheMe`] bot adaptor
46//! - `full` — enables all features except `nightly` and tls-related
47//! - `nightly` — enables nightly-only features, currently:
48//! - Removes some future boxing using `#![feature(type_alias_impl_trait)]`
49//! - Used to built docs (`#![feature(doc_cfg, doc_notable_trait)]`)
50//!
51//! [`Trace`]: adaptors::Trace
52//! [`ErasedRequester`]: adaptors::ErasedRequester
53//! [`Throttle`]: adaptors::Throttle
54//! [`CacheMe`]: adaptors::CacheMe
55//! [`native-tls`]: https://docs.rs/native-tls
56//! [`rustls`]: https://docs.rs/rustls
57
58#![doc(
59 // FIXME(waffle): use github
60 html_logo_url = "https://cdn.discordapp.com/attachments/224881373326999553/798598120760934410/logo.png",
61 html_favicon_url = "https://cdn.discordapp.com/attachments/224881373326999553/798598120760934410/logo.png"
62)]
63//
64// we pass "--cfg docsrs" when building docs to add `This is supported on feature="..." only.`
65//
66// To properly build docs of this crate run
67// ```console
68// $ cargo docs
69// ```
70// (docs alias is defined in `.cargo/config.toml`)
71//
72// `dep_docsrs` is used for the same purpose, but when `teloxide-core` is built as a dependency
73// (see: `teloxide`). We can't use `docsrs` as it breaks tokio compilation in this case.
74#![cfg_attr(all(any(docsrs, dep_docsrs), feature = "nightly"), feature(doc_cfg, doc_notable_trait))]
75#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))]
76#![cfg_attr(all(feature = "full", docsrs), deny(rustdoc::broken_intra_doc_links))]
77//
78// Lint levels
79#![forbid(unsafe_code)]
80//#![deny(missing_docs)]
81#![warn(clippy::print_stdout, clippy::dbg_macro)]
82#![allow(
83 // Sometimes it's more readable to assign to a variable and return it immediately
84 clippy::let_and_return,
85
86 // When you are testing ->bool functions, it makes sense to `assert_eq!(f(..), false)`
87 clippy::bool_assert_comparison,
88
89 // Unless this becomes machine applicable, I'm not adding 334 #[must_use]s (waffle)
90 clippy::return_self_not_must_use,
91
92 // This is dumb. `T: ?Sized where T: Trait` IMO makes perfect sense
93 clippy::multiple_bound_locations,
94
95 // Workaround for CI
96 // FIXME: do we still need this?
97 rustdoc::bare_urls,
98
99 // FIXME: deal with these lints
100 clippy::collapsible_str_replace,
101 clippy::borrow_deref_ref,
102 clippy::unnecessary_lazy_evaluations,
103 clippy::derive_partial_eq_without_eq
104)]
105
106// The internal helper macros.
107#[macro_use]
108mod local_macros;
109
110pub use self::{
111 bot::Bot,
112 errors::{ApiError, DownloadError, RequestError},
113};
114
115pub mod adaptors;
116pub mod errors;
117pub mod net;
118pub mod payloads;
119pub mod prelude;
120pub mod requests;
121pub mod types;
122
123// reexported
124mod bot;
125
126// implementation details
127mod serde_multipart;
128mod util;
129
130#[cfg(test)]
131mod codegen;