teloxide_core/
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.82+_.
11//!
12//! ```
13//! # async {
14//! # let chat_id = teloxide_core::types::ChatId(-1);
15//! use teloxide_core::{
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(
75    all(any(docsrs, dep_docsrs), feature = "nightly"),
76    feature(doc_cfg, doc_auto_cfg, doc_notable_trait)
77)]
78#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))]
79#![cfg_attr(all(feature = "full", docsrs), deny(rustdoc::broken_intra_doc_links))]
80//
81// Lint levels
82#![forbid(unsafe_code)]
83//#![deny(missing_docs)]
84#![warn(clippy::print_stdout, clippy::dbg_macro)]
85#![allow(
86    // Sometimes it's more readable to assign to a variable and return it immediately
87    clippy::let_and_return,
88
89    // When you are testing ->bool functions, it makes sense to `assert_eq!(f(..), false)`
90    clippy::bool_assert_comparison,
91
92    // Unless this becomes machine applicable, I'm not adding 334 #[must_use]s (waffle)
93    clippy::return_self_not_must_use,
94
95    // This is dumb. `T: ?Sized where T: Trait` IMO makes perfect sense
96    clippy::multiple_bound_locations,
97
98    // Workaround for CI
99    // FIXME: do we still need this?
100    rustdoc::bare_urls,
101
102    // FIXME: deal with these lints
103    clippy::collapsible_str_replace,
104    clippy::borrow_deref_ref,
105    clippy::unnecessary_lazy_evaluations,
106    clippy::derive_partial_eq_without_eq
107)]
108
109// The internal helper macros.
110#[macro_use]
111mod local_macros;
112
113pub use self::{
114    bot::Bot,
115    errors::{ApiError, DownloadError, RequestError},
116};
117
118pub mod adaptors;
119pub mod errors;
120pub mod net;
121pub mod payloads;
122pub mod prelude;
123pub mod requests;
124pub mod types;
125
126// reexported
127mod bot;
128
129// implementation details
130mod serde_multipart;
131mod util;
132
133#[cfg(test)]
134mod codegen;