teloxide/crates/teloxide-core/src/lib.rs

123 lines
3.9 KiB
Rust
Raw Normal View History

2021-01-15 21:51:15 +03:00
//! Core part of the [`teloxide`] library.
//!
//! This library provides tools for making requests to the [Telegram Bot API]
2023-01-14 20:28:50 +04:00
//! (Currently, version `6.4` is supported) with ease. The library is fully
2022-03-24 21:32:01 +04:00
//! asynchronous and built using [`tokio`].
2021-01-15 21:51:15 +03:00
//!
//!```toml
2022-10-03 00:08:00 +00:00
//! teloxide_core = "0.8"
2021-01-15 21:51:15 +03:00
//! ```
2022-09-23 18:58:02 +04:00
//! _Compiler support: requires rustc 1.64+_.
2021-01-15 21:51:15 +03:00
//!
//! ```
//! # async {
//! # let chat_id = teloxide_core::types::ChatId(-1);
2021-01-15 21:51:15 +03:00
//! use teloxide_core::{
//! prelude::*,
//! types::{DiceEmoji, ParseMode},
//! };
//!
2022-09-23 22:48:24 +04:00
//! let bot = Bot::from_env().parse_mode(ParseMode::MarkdownV2);
2021-01-15 21:51:15 +03:00
//!
//! let me = bot.get_me().await?;
//!
2021-01-21 10:15:02 +03:00
//! bot.send_dice(chat_id).emoji(DiceEmoji::Dice).await?;
2022-11-07 16:13:29 +04:00
//! bot.send_message(chat_id, format!("Hi, my name is **{}** 👋", me.user.first_name)).await?;
2021-01-15 21:51:15 +03:00
//! # Ok::<_, Box<dyn std::error::Error>>(()) };
//! ```
//!
//! <div align="center">
//! <img src=https://user-images.githubusercontent.com/38225716/103929465-6b91e100-512e-11eb-826d-39b096f16548.gif />
//! </div>
//!
//! [`teloxide`]: https://docs.rs/teloxide
//! [Telegram Bot API]: https://core.telegram.org/bots/api
//! [`tokio`]: https://tokio.rs
//!
//! ## Cargo features
//!
2021-01-26 11:56:42 +03:00
//! - `native-tls` = use [`native-tls`] tls implementation (**enabled by
//! default**)
//! - `rustls` — use [`rustls`] tls implementation
2021-07-11 15:58:09 +03:00
//! - `trace_adaptor` — enables [`Trace`] bot adaptor
2021-07-12 16:58:51 +03:00
//! - `erased` — enables [`ErasedRequester`] bot adaptor
2021-01-15 21:51:15 +03:00
//! - `throttle` — enables [`Throttle`] bot adaptor
//! - `cache_me` — enables [`CacheMe`] bot adaptor
2022-03-24 21:32:01 +04:00
//! - `full` — enables all features except `nightly` and tls-related
//! - `nightly` — enables nightly-only features, currently:
2021-01-15 21:51:15 +03:00
//! - Removes some future boxing using `#![feature(type_alias_impl_trait)]`
//! - Used to built docs (`#![feature(doc_cfg, doc_notable_trait)]`)
2022-09-23 18:40:07 +04:00
//! - `auto_send` — enables [`AutoSend`] bot adaptor (deprecated)
2021-01-15 21:51:15 +03:00
//!
//! [`AutoSend`]: adaptors::AutoSend
2021-07-11 15:58:09 +03:00
//! [`Trace`]: adaptors::Trace
2021-07-12 16:58:51 +03:00
//! [`ErasedRequester`]: adaptors::ErasedRequester
2021-01-15 21:51:15 +03:00
//! [`Throttle`]: adaptors::Throttle
//! [`CacheMe`]: adaptors::CacheMe
2021-01-26 11:56:42 +03:00
//! [`native-tls`]: https://docs.rs/native-tls
//! [`rustls`]: https://docs.rs/rustls
2020-08-12 18:04:50 +03:00
2021-01-15 21:51:15 +03:00
#![doc(
// FIXME(waffle): use github
html_logo_url = "https://cdn.discordapp.com/attachments/224881373326999553/798598120760934410/logo.png",
html_favicon_url = "https://cdn.discordapp.com/attachments/224881373326999553/798598120760934410/logo.png"
)]
#![forbid(unsafe_code)]
2020-08-12 18:04:50 +03:00
// we pass "--cfg docsrs" when building docs to add `This is supported on feature="..." only.`
//
// To properly build docs of this crate run
// ```console
// $ cargo docs
2020-08-12 18:04:50 +03:00
// ```
// (docs alias is defined in `.cargo/config.toml`)
//
// `dep_docsrs` is used for the same purpose, but when `teloxide-core` is built as a dependency
// (see: `teloxide`). We can't use `docsrs` as it breaks tokio compilation in this case.
#![cfg_attr(
all(any(docsrs, dep_docsrs), feature = "nightly"),
2022-01-02 19:20:56 +03:00
feature(doc_cfg, doc_auto_cfg, doc_notable_trait)
)]
#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))]
2021-03-16 14:06:22 +03:00
#![cfg_attr(all(feature = "full", docsrs), deny(rustdoc::broken_intra_doc_links))]
2020-08-12 19:39:40 +03:00
//#![deny(missing_docs)]
#![warn(clippy::print_stdout, clippy::dbg_macro)]
#![allow(clippy::let_and_return)]
2022-09-29 13:15:01 +04:00
#![allow(clippy::bool_assert_comparison)]
2021-12-19 14:56:20 +03:00
// Unless this becomes machine applicable, I'm not adding 334 #[must_use]s (waffle)
#![allow(clippy::return_self_not_must_use)]
2022-06-28 20:12:36 +04:00
// Workaround for CI
#![allow(rustdoc::bare_urls)]
2022-09-23 22:59:04 +04:00
// FIXME: deal with these lints
#![allow(
clippy::collapsible_str_replace,
clippy::borrow_deref_ref,
clippy::unnecessary_lazy_evaluations,
clippy::derive_partial_eq_without_eq
)]
// The internal helper macros.
#[macro_use]
mod local_macros;
2020-08-12 19:39:40 +03:00
pub use self::{
bot::Bot,
2020-10-20 15:07:10 +03:00
errors::{ApiError, DownloadError, RequestError},
2020-08-12 19:39:40 +03:00
};
pub mod adaptors;
pub mod errors;
pub mod net;
2020-09-22 22:52:23 +03:00
pub mod payloads;
pub mod prelude;
2020-08-12 19:39:40 +03:00
pub mod requests;
pub mod types;
2020-08-12 19:39:40 +03:00
// reexported
mod bot;
2020-08-12 19:39:40 +03:00
// implementation details
mod serde_multipart;
2022-08-09 21:07:18 +04:00
#[cfg(test)]
mod codegen;