diff --git a/crates/teloxide-core/src/requests/requester.rs b/crates/teloxide-core/src/requests/requester.rs index 3fc819bb..f4a29663 100644 --- a/crates/teloxide-core/src/requests/requester.rs +++ b/crates/teloxide-core/src/requests/requester.rs @@ -90,8 +90,8 @@ use crate::{ /// /// Because of this it's oftentimes more convinient to have a type alias: /// -/// ```rust -/// # async { +/// ```rust,no_run +/// # #[cfg(feature = "throttle")] { /// # use teloxide_core::{adaptors::{DefaultParseMode, Throttle}, requests::RequesterExt, types::ParseMode}; /// type Bot = DefaultParseMode>; /// diff --git a/crates/teloxide/Cargo.toml b/crates/teloxide/Cargo.toml index a9ea94dc..760b14ad 100644 --- a/crates/teloxide/Cargo.toml +++ b/crates/teloxide/Cargo.toml @@ -137,41 +137,49 @@ required-features = ["sqlite-storage", "cbor-serializer", "bincode-serializer"] [[example]] -name = "dialogue" -required-features = ["macros"] +name = "admin" +required-features = ["macros", "ctrlc_handler"] + +[[example]] +name = "buttons" +required-features = ["macros", "ctrlc_handler"] [[example]] name = "command" -required-features = ["macros"] +required-features = ["macros", "ctrlc_handler"] [[example]] name = "db_remember" required-features = ["sqlite-storage", "redis-storage", "bincode-serializer", "macros"] [[example]] -name = "inline" -required-features = ["macros"] - -[[example]] -name = "buttons" -required-features = ["macros"] - -[[example]] -name = "admin" -required-features = ["macros"] +name = "dialogue" +required-features = ["macros", "ctrlc_handler"] [[example]] name = "dispatching_features" -required-features = ["macros"] - -[[example]] -name = "ngrok_ping_pong" -required-features = ["webhooks-axum"] +required-features = ["macros", "ctrlc_handler"] [[example]] name = "heroku_ping_pong" -required-features = ["webhooks-axum"] +required-features = ["webhooks-axum", "ctrlc_handler"] + +[[example]] +name = "inline" +required-features = ["macros", "ctrlc_handler"] + +[[example]] +name = "ngrok_ping_pong" +required-features = ["webhooks-axum", "ctrlc_handler"] [[example]] name = "purchase" -required-features = ["macros"] +required-features = ["macros", "ctrlc_handler"] + +[[example]] +name = "shared_state" +required-features = ["ctrlc_handler"] + +[[example]] +name = "throw_dice" +required-features = ["ctrlc_handler"] diff --git a/crates/teloxide/src/dispatching.rs b/crates/teloxide/src/dispatching.rs index 5138e398..3d64ef8e 100644 --- a/crates/teloxide/src/dispatching.rs +++ b/crates/teloxide/src/dispatching.rs @@ -23,6 +23,7 @@ //! `/start` or `/help`: //! //! ```no_run +//! # #[cfg(feature = "macros")] { //! # use teloxide::utils::command::BotCommands; //! #[derive(BotCommands, Clone)] //! #[command(rename_rule = "lowercase", description = "These commands are supported:")] @@ -34,6 +35,7 @@ //! #[command(description = "cancel the purchase procedure.")] //! Cancel, //! } +//! # } //! ``` //! //! Now the key question: how to elegantly dispatch on different combinations of @@ -43,6 +45,7 @@ //! solution is to use [`dptree`]: //! //! ```no_run +//! # #[cfg(feature = "macros")] { //! # // That's a lot of context needed to compile this, oof //! # use teloxide::dispatching::{UpdateHandler, UpdateFilterExt, dialogue, dialogue::InMemStorage}; //! # use teloxide::utils::command::BotCommands; @@ -81,6 +84,7 @@ //! .branch(message_handler) //! .branch(callback_query_handler) //! } +//! # } //! ``` //! //! The overall logic should be clear. Throughout the above example, we use @@ -149,6 +153,7 @@ //! Inside `main`, we plug the schema into [`Dispatcher`] like this: //! //! ```no_run +//! # #[cfg(feature = "ctrlc_handler")] { //! # use teloxide::Bot; //! # use teloxide::requests::RequesterExt; //! # use teloxide::dispatching::{Dispatcher, dialogue::InMemStorage}; @@ -165,6 +170,7 @@ //! .dispatch() //! .await; //! } +//! # } //! ``` //! //! In a call to [`DispatcherBuilder::dependencies`], we specify a list of diff --git a/crates/teloxide/src/dispatching/handler_description.rs b/crates/teloxide/src/dispatching/handler_description.rs index 92bbda38..55b4146d 100644 --- a/crates/teloxide/src/dispatching/handler_description.rs +++ b/crates/teloxide/src/dispatching/handler_description.rs @@ -77,14 +77,15 @@ impl EventKind for Kind { #[cfg(test)] mod tests { + #[cfg(feature = "macros")] use crate::{ + self as teloxide, // fixup for the `BotCommands` macro dispatching::{HandlerExt, UpdateFilterExt}, types::{AllowedUpdate::*, Update}, utils::command::BotCommands, }; - use crate as teloxide; // fixup for the `BotCommands` macro - + #[cfg(feature = "macros")] #[derive(BotCommands, Clone)] #[command(rename_rule = "lowercase")] enum Cmd { @@ -93,6 +94,7 @@ mod tests { // #[test] + #[cfg(feature = "macros")] fn discussion_648() { let h = dptree::entry().branch(Update::filter_my_chat_member().endpoint(|| async {})).branch( @@ -108,4 +110,11 @@ mod tests { assert_eq!(v, [Message, MyChatMember]) } + + #[test] + #[ignore = "this test requires `macros` feature"] + #[cfg(not(feature = "macros"))] + fn discussion_648() { + panic!("this test requires `macros` feature") + } } diff --git a/crates/teloxide/src/lib.rs b/crates/teloxide/src/lib.rs index 2fc500d9..77a67781 100644 --- a/crates/teloxide/src/lib.rs +++ b/crates/teloxide/src/lib.rs @@ -6,8 +6,10 @@ //! //! [[`examples/throw_dice.rs`](https://github.com/teloxide/teloxide/blob/master/examples/throw_dice.rs)] //! ```no_run +//! # #[cfg(feature = "ctrlc_handler")] //! use teloxide::prelude::*; //! +//! # #[cfg(feature = "ctrlc_handler")] //! # #[tokio::main] //! # async fn main() { //! pretty_env_logger::init(); @@ -20,7 +22,7 @@ //! Ok(()) //! }) //! .await; -//! # } +//! # } #[cfg(not(feature = "ctrlc_handler"))] fn main(){} //! ``` //! //!