ronami_core/lib.rs
1//! Core part of the [`ronami`] library.
2//!
3//! This library provides tools for making requests to the [Telegram Bot API]
4//! (Currently, version `10.3` is supported) with ease. The library is fully
5//! asynchronous and built using [`tokio`].
6//!
7//!```toml
8//! ronami-core = "1.5.0"
9//! ```
10//! _Compiler support: requires rustc 1.85+_.
11//!
12//! ```
13//! # async {
14//! # let chat_id = ronami_core::types::ChatId(-1);
15//! use ronami_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//! [`ronami`]: https://docs.rs/ronami
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 html_logo_url = "https://raw.githubusercontent.com/ZethRise/Ronami/master/media/ronami-core-logo.png",
60 html_favicon_url = "https://raw.githubusercontent.com/ZethRise/Ronami/master/media/ronami-core-logo.png"
61)]
62//
63// we pass "--cfg docsrs" when building docs to add `This is supported on feature="..." only.`
64//
65// To properly build docs of this crate run
66// ```console
67// $ cargo docs
68// ```
69// (docs alias is defined in `.cargo/config.toml`)
70//
71// `dep_docsrs` is used for the same purpose, but when `ronami-core` is built as a dependency
72// (see: `ronami`). We can't use `docsrs` as it breaks tokio compilation in this case.
73#![cfg_attr(all(any(docsrs, dep_docsrs), feature = "nightly"), feature(doc_cfg, doc_notable_trait))]
74#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))]
75#![cfg_attr(all(feature = "full", docsrs), deny(rustdoc::broken_intra_doc_links))]
76//
77// Lint levels
78#![forbid(unsafe_code)]
79//#![deny(missing_docs)]
80#![warn(clippy::print_stdout, clippy::dbg_macro)]
81#![allow(
82 // Sometimes it's more readable to assign to a variable and return it immediately
83 clippy::let_and_return,
84
85 // When you are testing ->bool functions, it makes sense to `assert_eq!(f(..), false)`
86 clippy::bool_assert_comparison,
87
88 // Unless this becomes machine applicable, I'm not adding 334 #[must_use]s (waffle)
89 clippy::return_self_not_must_use,
90
91 // This is dumb. `T: ?Sized where T: Trait` IMO makes perfect sense
92 clippy::multiple_bound_locations,
93
94 // Workaround for CI
95 // FIXME: do we still need this?
96 rustdoc::bare_urls,
97
98 // FIXME: deal with these lints
99 clippy::collapsible_str_replace,
100 clippy::borrow_deref_ref,
101 clippy::unnecessary_lazy_evaluations,
102 clippy::derive_partial_eq_without_eq
103)]
104
105// The internal helper macros.
106#[macro_use]
107mod local_macros;
108
109pub use self::{
110 bot::Bot,
111 errors::{ApiError, DownloadError, RequestError},
112};
113
114pub mod adaptors;
115pub mod errors;
116pub mod net;
117pub mod payloads;
118pub mod prelude;
119pub mod requests;
120pub mod types;
121
122// reexported
123mod bot;
124
125// implementation details
126mod serde_multipart;
127mod util;
128
129#[cfg(test)]
130mod codegen;