From 599d4dea25826257c2531f417c35a17fbadc331c Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 9 Sep 2022 23:54:52 +0400 Subject: [PATCH 1/8] Update docs of REPLs Former-commit-id: bde0345e17ad1f4ad094fd1271bf5d2e30e4f329 --- src/dispatching/repls.rs | 9 +- src/dispatching/repls/caution.md | 2 + src/dispatching/repls/commands_repl.rs | 126 +++++++++++++++++-------- src/dispatching/repls/preamble.md | 7 ++ src/dispatching/repls/repl.rs | 123 +++++++++++++++--------- src/dispatching/repls/stopping.md | 4 + 6 files changed, 185 insertions(+), 86 deletions(-) create mode 100644 src/dispatching/repls/caution.md create mode 100644 src/dispatching/repls/preamble.md create mode 100644 src/dispatching/repls/stopping.md diff --git a/src/dispatching/repls.rs b/src/dispatching/repls.rs index b0f450a3..0d41d7ba 100644 --- a/src/dispatching/repls.rs +++ b/src/dispatching/repls.rs @@ -1,4 +1,11 @@ -//! REPLs for dispatching updates. +//! [REPL]s for dispatching updates. +//! +//! This module provides functions for easy update handling, that accept a +//! single "handler" function that processes all updates of a certain kind. Note +//! that REPLs are meant to be used as a prototyping tool and lack configuration +//! and some advanced features. +//! +//! [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop mod commands_repl; mod repl; diff --git a/src/dispatching/repls/caution.md b/src/dispatching/repls/caution.md new file mode 100644 index 00000000..a5968cb3 --- /dev/null +++ b/src/dispatching/repls/caution.md @@ -0,0 +1,2 @@ +**DO NOT** use this function together with [`Dispatcher`] and other REPLs, +because Telegram disallow multiple requests at the same time from the same bot. diff --git a/src/dispatching/repls/commands_repl.rs b/src/dispatching/repls/commands_repl.rs index ceeeb917..b5dd39e7 100644 --- a/src/dispatching/repls/commands_repl.rs +++ b/src/dispatching/repls/commands_repl.rs @@ -11,36 +11,57 @@ use std::{fmt::Debug, marker::PhantomData}; use teloxide_core::requests::Requester; /// A [REPL] for commands. -/// -/// All errors from an update listener and handler will be logged. -/// -/// REPLs are meant only for simple bots and rapid prototyping. If you need to -/// supply dependencies or describe more complex dispatch logic, please use -/// [`Dispatcher`]. -/// -/// See also: ["Dispatching or -/// REPLs?"](dispatching/index.html#dispatching-or-repls) -/// -/// ## Caution -/// -/// **DO NOT** use this function together with [`Dispatcher`] and other REPLs, -/// because Telegram disallow multiple requests at the same time from the same -/// bot. -/// -/// ## Dependency requirements -/// -/// - Those of [`HandlerExt::filter_command`] +// +#[doc = include_str!("preamble.md")] /// /// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop -/// [`Dispatcher`]: crate::dispatching::Dispatcher +/// +/// ## Signature +/// +/// Don't be scared by many trait bounds in the signature, in essence they +/// require: +/// +/// 1. `bot` is a bot, client for the Telegram bot API +/// - in teloxide this is represented via a [`Requester`] trait +/// 2. `handler` is an async function that returns `Result<(), E>` +/// - Such that `E` can be printed with [`Debug`] formatting +/// - And all arguments can be extracted from [`DependencyMap`] +/// - Which is the same, as all arguments implementing `Send + Sync + +/// 'static` +/// 3. `cmd` is a type of the command that will be parsed, +/// - The command type must implement [`BotCommands`] trait +/// - It can be acquired by writing `TheCommandType::ty()` +/// +/// All other requirements are about thread safety and data validity and can be +/// ignored for most of the time. +/// +/// ## Handler arguments +/// +/// Teloxide provides the following types to the `handler`: +/// - [`Message`] +/// - `R` (type of the `bot`) +/// - `Cmd` (type of the parsed command) +/// - [`Me`] +/// +/// [`Me`]: crate::types::Me +/// [`Message`]: crate::types::Message +/// +/// ## Stopping +// +#[doc = include_str!("stopping.md")] +/// +/// ## Caution +// +#[doc = include_str!("caution.md")] +/// #[cfg(feature = "ctrlc_handler")] pub async fn commands_repl<'a, R, Cmd, H, E, Args>(bot: R, handler: H, cmd: PhantomData) where - Cmd: BotCommands + Send + Sync + 'static, - H: Injectable, Args> + Send + Sync + 'static, R: Requester + Clone + Send + Sync + 'static, ::GetUpdates: Send, + H: Injectable, Args> + Send + Sync + 'static, E: Debug + Send + Sync + 'static, + Cmd: BotCommands + Send + Sync + 'static, { let cloned_bot = bot.clone(); @@ -53,36 +74,57 @@ where .await; } -/// Like [`commands_repl`], but with a custom [`UpdateListener`]. +/// A [REPL] for commands, with a custom [`UpdateListener`]. +// +#[doc = include_str!("preamble.md")] /// -/// All errors from an update listener and handler will be logged. +/// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop /// -/// REPLs are meant only for simple bots and rapid prototyping. If you need to -/// supply dependencies or describe more complex dispatch logic, please use -/// [`Dispatcher`]. +/// ## Signature /// -/// See also: ["Dispatching or -/// REPLs?"](dispatching/index.html#dispatching-or-repls) +/// Don't be scared by many trait bounds in the signature, in essence they +/// require: +/// +/// 1. `bot` is a bot, client for the Telegram bot API +/// - in teloxide this is represented via a [`Requester`] trait +/// 2. `handler` is an async function that returns `Result<(), E>` +/// - Such that `E` can be printed with [`Debug`] formatting +/// - And all arguments can be extracted from [`DependencyMap`] +/// - Which is the same, as all arguments implementing `Send + Sync + +/// 'static` +/// 3. `listener` is an [`UpdateListener`] +/// 4. `cmd` is a type of the command that will be parsed, +/// - The command type must implement [`BotCommands`] trait +/// - It can be acquired by writing `TheCommandType::ty()` +/// +/// All other requirements are about thread safety and data validity and can be +/// ignored for most of the time. +/// +/// ## Handler arguments +/// +/// Teloxide provides the following types to the `handler`: +/// - [`Message`] +/// - `R` (type of the `bot`) +/// - `Cmd` (type of the parsed command) +/// - [`Me`] +/// +/// [`Me`]: crate::types::Me +/// [`Message`]: crate::types::Message +/// +/// ## Stopping +// +#[doc = include_str!("stopping.md")] /// /// ## Caution +// +#[doc = include_str!("caution.md")] /// -/// **DO NOT** use this function together with [`Dispatcher`] and other REPLs, -/// because Telegram disallow multiple requests at the same time from the same -/// bot. -/// -/// ## Dependency requirements -/// -/// - Those of [`HandlerExt::filter_command`] -/// -/// [`Dispatcher`]: crate::dispatching::Dispatcher -/// [`commands_repl`]: crate::dispatching::repls::commands_repl() -/// [`UpdateListener`]: crate::dispatching::update_listeners::UpdateListener #[cfg(feature = "ctrlc_handler")] pub async fn commands_repl_with_listener<'a, R, Cmd, H, L, E, Args>( bot: R, handler: H, listener: L, - _cmd: PhantomData, + cmd: PhantomData, ) where Cmd: BotCommands + Send + Sync + 'static, H: Injectable, Args> + Send + Sync + 'static, @@ -93,6 +135,8 @@ pub async fn commands_repl_with_listener<'a, R, Cmd, H, L, E, Args>( { use crate::dispatching::Dispatcher; + let _ = cmd; + // Other update types are of no interest to use since this REPL is only for // commands. See . let ignore_update = |_upd| Box::pin(async {}); diff --git a/src/dispatching/repls/preamble.md b/src/dispatching/repls/preamble.md new file mode 100644 index 00000000..5c21f079 --- /dev/null +++ b/src/dispatching/repls/preamble.md @@ -0,0 +1,7 @@ +REPLs are meant only for simple bots and rapid prototyping. +If you need to supply dependencies or describe more complex dispatch logic, please use [`Dispatcher`]. +See also: ["Dispatching or REPLs?"](dispatching/index.html#dispatching-or-repls). + +[`Dispatcher`]: crate::dispatching::Dispatcher + +All errors from a the handler and will be logged. diff --git a/src/dispatching/repls/repl.rs b/src/dispatching/repls/repl.rs index 529cc711..a755708f 100644 --- a/src/dispatching/repls/repl.rs +++ b/src/dispatching/repls/repl.rs @@ -1,6 +1,6 @@ use crate::{ dispatching::{update_listeners, update_listeners::UpdateListener, UpdateFilterExt}, - error_handlers::{LoggingErrorHandler, OnError}, + error_handlers::LoggingErrorHandler, types::Update, }; use dptree::di::{DependencyMap, Injectable}; @@ -8,66 +8,101 @@ use std::fmt::Debug; use teloxide_core::requests::Requester; /// A [REPL] for messages. -/// -/// All errors from an update listener and a handler will be logged. -/// -/// REPLs are meant only for simple bots and rapid prototyping. If you need to -/// supply dependencies or describe more complex dispatch logic, please use -/// [`Dispatcher`]. -/// -/// See also: ["Dispatching or -/// REPLs?"](dispatching/index.html#dispatching-or-repls) -/// -/// ## Caution -/// -/// **DO NOT** use this function together with [`Dispatcher`] and other REPLs, -/// because Telegram disallow multiple requests at the same time from the same -/// bot. +// +#[doc = include_str!("preamble.md")] /// /// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop -/// [`Dispatcher`]: crate::dispatching::Dispatcher +/// +/// ## Signature +/// +/// Don't be scared by many trait bounds in the signature, in essence they +/// require: +/// +/// 1. `bot` is a bot, client for the Telegram bot API +/// - in teloxide this is represented via a [`Requester`] trait +/// 2. `handler` is an async function that returns `Result<(), E>` +/// - Such that `E` can be printed with [`Debug`] formatting +/// - And all arguments can be extracted from [`DependencyMap`] +/// - Which is the same, as all arguments implementing `Send + Sync + +/// 'static` +/// +/// ## Handler arguments +/// +/// Teloxide provides the following types to the `handler`: +/// - [`Message`] +/// - `R` (type of the `bot`) +/// - [`Me`] +/// +/// [`Me`]: crate::types::Me +/// [`Message`]: crate::types::Message +/// +/// ## Stopping +// +#[doc = include_str!("stopping.md")] +/// +/// ## Caution +// +#[doc = include_str!("caution.md")] +/// #[cfg(feature = "ctrlc_handler")] pub async fn repl(bot: R, handler: H) where - H: Injectable, Args> + Send + Sync + 'static, - Result<(), E>: OnError, - E: Debug + Send + Sync + 'static, R: Requester + Send + Sync + Clone + 'static, ::GetUpdates: Send, + H: Injectable, Args> + Send + Sync + 'static, + E: Debug + Send + Sync + 'static, { let cloned_bot = bot.clone(); repl_with_listener(bot, handler, update_listeners::polling_default(cloned_bot).await).await; } -/// Like [`repl`], but with a custom [`UpdateListener`]. +/// A [REPL] for messages, with a custom [`UpdateListener`]. +// +#[doc = include_str!("preamble.md")] /// -/// All errors from an update listener and handler will be logged. -/// -/// REPLs are meant only for simple bots and rapid prototyping. If you need to -/// supply dependencies or describe more complex dispatch logic, please use -/// [`Dispatcher`]. -/// -/// See also: ["Dispatching or -/// REPLs?"](dispatching/index.html#dispatching-or-repls) -/// -/// # Caution -/// -/// **DO NOT** use this function together with [`Dispatcher`] and other REPLs, -/// because Telegram disallow multiple requests at the same time from the same -/// bot. -/// -/// [`Dispatcher`]: crate::dispatching::Dispatcher -/// [`repl`]: crate::dispatching::repls::repl() +/// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop /// [`UpdateListener`]: crate::dispatching::update_listeners::UpdateListener +/// +/// ## Signature +/// +/// Don't be scared by many trait bounds in the signature, in essence they +/// require: +/// +/// 1. `bot` is a bot, client for the Telegram bot API +/// - in teloxide this is represented via a [`Requester`] trait +/// 2. `handler` is an async function that returns `Result<(), E>` +/// - Such that `E` can be printed with [`Debug`] formatting +/// - And all arguments can be extracted from [`DependencyMap`] +/// - Which is the same, as all arguments implementing `Send + Sync + +/// 'static` +/// 3. `listener` is an [`UpdateListener`] +/// +/// ## Handler arguments +/// +/// Teloxide provides the following types to the `handler`: +/// - [`Message`] +/// - `R` (type of the `bot`) +/// - [`Me`] +/// +/// [`Me`]: crate::types::Me +/// [`Message`]: crate::types::Message +/// +/// ## Stopping +// +#[doc = include_str!("stopping.md")] +/// +/// ## Caution +// +#[doc = include_str!("caution.md")] +/// #[cfg(feature = "ctrlc_handler")] -pub async fn repl_with_listener<'a, R, H, E, L, Args>(bot: R, handler: H, listener: L) +pub async fn repl_with_listener(bot: R, handler: H, listener: L) where - H: Injectable, Args> + Send + Sync + 'static, - L: UpdateListener + Send + 'a, - L::Err: Debug, - Result<(), E>: OnError, - E: Debug + Send + Sync + 'static, R: Requester + Clone + Send + Sync + 'static, + H: Injectable, Args> + Send + Sync + 'static, + E: Debug + Send + Sync + 'static, + L: UpdateListener + Send, + L::Err: Debug, { use crate::dispatching::Dispatcher; diff --git a/src/dispatching/repls/stopping.md b/src/dispatching/repls/stopping.md new file mode 100644 index 00000000..63c65e28 --- /dev/null +++ b/src/dispatching/repls/stopping.md @@ -0,0 +1,4 @@ +To stop repl, simply press `Ctrl`+`C` in the terminal where you run the program. +Note that gracefully stopping can take some time (we plan to improve this, see [#711]). + +[#711]: https://github.com/teloxide/teloxide/issues/711 From a3632d65dab0a5f96b837f4118adaafab3b304cc Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 7 Oct 2022 12:03:34 +0400 Subject: [PATCH 2/8] Apply suggestions from code review Former-commit-id: 83d3a11be9702838bc0322b985d4e29b7f510d89 --- src/dispatching/repls.rs | 6 ++-- src/dispatching/repls/commands_repl.rs | 46 ++++++++++++-------------- src/dispatching/repls/repl.rs | 25 ++++++-------- src/dispatching/repls/stopping.md | 4 +-- 4 files changed, 36 insertions(+), 45 deletions(-) diff --git a/src/dispatching/repls.rs b/src/dispatching/repls.rs index 0d41d7ba..18fac935 100644 --- a/src/dispatching/repls.rs +++ b/src/dispatching/repls.rs @@ -1,9 +1,9 @@ //! [REPL]s for dispatching updates. //! -//! This module provides functions for easy update handling, that accept a +//! This module provides utilities for easy update handling. They accept a //! single "handler" function that processes all updates of a certain kind. Note -//! that REPLs are meant to be used as a prototyping tool and lack configuration -//! and some advanced features. +//! that REPLs are meant to be used for simple scenarios, such as prototyping, +//! inasmuch they lack configuration and some advanced features. //! //! [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop diff --git a/src/dispatching/repls/commands_repl.rs b/src/dispatching/repls/commands_repl.rs index f3c25cfe..b988d06b 100644 --- a/src/dispatching/repls/commands_repl.rs +++ b/src/dispatching/repls/commands_repl.rs @@ -22,19 +22,17 @@ use teloxide_core::requests::Requester; /// Don't be scared by many trait bounds in the signature, in essence they /// require: /// -/// 1. `bot` is a bot, client for the Telegram bot API -/// - in teloxide this is represented via a [`Requester`] trait -/// 2. `handler` is an async function that returns `Result<(), E>` -/// - Such that `E` can be printed with [`Debug`] formatting -/// - And all arguments can be extracted from [`DependencyMap`] -/// - Which is the same, as all arguments implementing `Send + Sync + -/// 'static` -/// 3. `cmd` is a type of the command that will be parsed, -/// - The command type must implement [`BotCommands`] trait -/// - It can be acquired by writing `TheCommandType::ty()` +/// 1. `bot` is a bot, client for the Telegram bot API. It is represented via +/// the [`Requester`] trait. +/// 2. `handler` is an `async` function that takes arguments from +/// [`DependencyMap`] (see below) and returns [`ResponseResult`]. +/// 3. `cmd` is a type hint for your command enumeration +/// `MyCommand`: just write `MyCommand::ty()`. Note that `MyCommand` must +/// implement the [`BotCommands`] trait, typically via +/// `#[derive(BotCommands)]`. /// -/// All other requirements are about thread safety and data validity and can be -/// ignored for most of the time. +/// All the other requirements are about thread safety and data validity and can +/// be ignored for most of the time. /// /// ## Handler arguments /// @@ -85,20 +83,18 @@ where /// Don't be scared by many trait bounds in the signature, in essence they /// require: /// -/// 1. `bot` is a bot, client for the Telegram bot API -/// - in teloxide this is represented via a [`Requester`] trait -/// 2. `handler` is an async function that returns `Result<(), E>` -/// - Such that `E` can be printed with [`Debug`] formatting -/// - And all arguments can be extracted from [`DependencyMap`] -/// - Which is the same, as all arguments implementing `Send + Sync + -/// 'static` -/// 3. `listener` is an [`UpdateListener`] -/// 4. `cmd` is a type of the command that will be parsed, -/// - The command type must implement [`BotCommands`] trait -/// - It can be acquired by writing `TheCommandType::ty()` +/// 1. `bot` is a bot, client for the Telegram bot API. It is represented via +/// the [`Requester`] trait. +/// 2. `handler` is an `async` function that takes arguments from +/// [`DependencyMap`] (see below) and returns [`ResponseResult`]. +/// 3. `listener` is something that takes updates from a Telegram server and +/// implements [`UpdateListener`]. +/// 4. `cmd` is a type hint for your command enumeration `MyCommand`: just +/// write `MyCommand::ty()`. Note that `MyCommand` must implement the +/// [`BotCommands`] trait, typically via `#[derive(BotCommands)]`. /// -/// All other requirements are about thread safety and data validity and can be -/// ignored for most of the time. +/// All the other requirements are about thread safety and data validity and can +/// be ignored for most of the time. /// /// ## Handler arguments /// diff --git a/src/dispatching/repls/repl.rs b/src/dispatching/repls/repl.rs index 3a63d440..8edf5828 100644 --- a/src/dispatching/repls/repl.rs +++ b/src/dispatching/repls/repl.rs @@ -19,13 +19,10 @@ use teloxide_core::requests::Requester; /// Don't be scared by many trait bounds in the signature, in essence they /// require: /// -/// 1. `bot` is a bot, client for the Telegram bot API -/// - in teloxide this is represented via a [`Requester`] trait -/// 2. `handler` is an async function that returns `Result<(), E>` -/// - Such that `E` can be printed with [`Debug`] formatting -/// - And all arguments can be extracted from [`DependencyMap`] -/// - Which is the same, as all arguments implementing `Send + Sync + -/// 'static` +/// 1. `bot` is a bot, client for the Telegram bot API. It is represented via +/// the [`Requester`] trait. +/// 2. `handler` is an `async` function that takes arguments from +/// [`DependencyMap`] (see below) and returns [`ResponseResult`]. /// /// ## Handler arguments /// @@ -68,14 +65,12 @@ where /// Don't be scared by many trait bounds in the signature, in essence they /// require: /// -/// 1. `bot` is a bot, client for the Telegram bot API -/// - in teloxide this is represented via a [`Requester`] trait -/// 2. `handler` is an async function that returns `Result<(), E>` -/// - Such that `E` can be printed with [`Debug`] formatting -/// - And all arguments can be extracted from [`DependencyMap`] -/// - Which is the same, as all arguments implementing `Send + Sync + -/// 'static` -/// 3. `listener` is an [`UpdateListener`] +/// 1. `bot` is a bot, client for the Telegram bot API. It is represented via +/// the [`Requester`] trait. +/// 2. `handler` is an `async` function that takes arguments from +/// [`DependencyMap`] (see below) and returns [`ResponseResult`]. +/// 3. `listener` is something that takes updates from a Telegram server and +/// implements [`UpdateListener`]. /// /// ## Handler arguments /// diff --git a/src/dispatching/repls/stopping.md b/src/dispatching/repls/stopping.md index 63c65e28..b5733e84 100644 --- a/src/dispatching/repls/stopping.md +++ b/src/dispatching/repls/stopping.md @@ -1,4 +1,4 @@ -To stop repl, simply press `Ctrl`+`C` in the terminal where you run the program. -Note that gracefully stopping can take some time (we plan to improve this, see [#711]). +To stop a REPL, simply press `Ctrl`+`C` in the terminal where you run the program. +Note that graceful shutdown may take some time (we plan to improve this, see [#711]). [#711]: https://github.com/teloxide/teloxide/issues/711 From bb686ebd8ebf8008d49e27385d7b65a59fe810a7 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 7 Oct 2022 12:19:54 +0400 Subject: [PATCH 3/8] fix docs Former-commit-id: d9b18abd5597180394898bdb45c32d0e9ca26f93 --- src/dispatching/repls/commands_repl.rs | 7 +++---- src/dispatching/repls/repl.rs | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/dispatching/repls/commands_repl.rs b/src/dispatching/repls/commands_repl.rs index b988d06b..9b136006 100644 --- a/src/dispatching/repls/commands_repl.rs +++ b/src/dispatching/repls/commands_repl.rs @@ -3,13 +3,12 @@ use crate::{ update_listeners, update_listeners::UpdateListener, HandlerExt, UpdateFilterExt, }, error_handlers::LoggingErrorHandler, + requests::{Requester, ResponseResult}, types::Update, utils::command::BotCommands, - RequestError, }; use dptree::di::{DependencyMap, Injectable}; use std::{fmt::Debug, marker::PhantomData}; -use teloxide_core::requests::Requester; /// A [REPL] for commands. // @@ -58,7 +57,7 @@ pub async fn commands_repl<'a, R, Cmd, H, Args>(bot: R, handler: H, cmd: Phantom where R: Requester + Clone + Send + Sync + 'static, ::GetUpdates: Send, - H: Injectable, Args> + Send + Sync + 'static, + H: Injectable, Args> + Send + Sync + 'static, Cmd: BotCommands + Send + Sync + 'static, { let cloned_bot = bot.clone(); @@ -123,7 +122,7 @@ pub async fn commands_repl_with_listener<'a, R, Cmd, H, L, Args>( cmd: PhantomData, ) where Cmd: BotCommands + Send + Sync + 'static, - H: Injectable, Args> + Send + Sync + 'static, + H: Injectable, Args> + Send + Sync + 'static, L: UpdateListener + Send + 'a, L::Err: Debug + Send + 'a, R: Requester + Clone + Send + Sync + 'static, diff --git a/src/dispatching/repls/repl.rs b/src/dispatching/repls/repl.rs index 8edf5828..1c6fd659 100644 --- a/src/dispatching/repls/repl.rs +++ b/src/dispatching/repls/repl.rs @@ -1,12 +1,11 @@ use crate::{ dispatching::{update_listeners, update_listeners::UpdateListener, UpdateFilterExt}, error_handlers::LoggingErrorHandler, + requests::{Requester, ResponseResult}, types::Update, - RequestError, }; use dptree::di::{DependencyMap, Injectable}; use std::fmt::Debug; -use teloxide_core::requests::Requester; /// A [REPL] for messages. // @@ -47,7 +46,7 @@ pub async fn repl(bot: R, handler: H) where R: Requester + Send + Sync + Clone + 'static, ::GetUpdates: Send, - H: Injectable, Args> + Send + Sync + 'static, + H: Injectable, Args> + Send + Sync + 'static, { let cloned_bot = bot.clone(); repl_with_listener(bot, handler, update_listeners::polling_default(cloned_bot).await).await; @@ -94,7 +93,7 @@ where pub async fn repl_with_listener(bot: R, handler: H, listener: L) where R: Requester + Clone + Send + Sync + 'static, - H: Injectable, Args> + Send + Sync + 'static, + H: Injectable, Args> + Send + Sync + 'static, L: UpdateListener + Send, L::Err: Debug, { From fde91dacf4543fe80b99d9e601e6ffa8e0d64614 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 7 Oct 2022 13:09:57 +0400 Subject: [PATCH 4/8] Apply suggestions from the review Former-commit-id: db22e202211071c8c7ff3184f8fcb9b9d61079e6 --- src/dispatching/repls/commands_repl.rs | 8 ++++++++ src/dispatching/repls/repl.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/dispatching/repls/commands_repl.rs b/src/dispatching/repls/commands_repl.rs index 9b136006..b4f98866 100644 --- a/src/dispatching/repls/commands_repl.rs +++ b/src/dispatching/repls/commands_repl.rs @@ -41,6 +41,10 @@ use std::{fmt::Debug, marker::PhantomData}; /// - `Cmd` (type of the parsed command) /// - [`Me`] /// +/// Each of these types can be accepted as a handler parameter. Note that they +/// aren't all required at the same time: e.g., you can take only the bot and +/// the command without [`Me`] and [`Message`]. +/// /// [`Me`]: crate::types::Me /// [`Message`]: crate::types::Message /// @@ -103,6 +107,10 @@ where /// - `Cmd` (type of the parsed command) /// - [`Me`] /// +/// Each of these types can be accepted as a handler parameter. Note that they +/// aren't all required at the same time: e.g., you can take only the bot and +/// the command without [`Me`] and [`Message`]. +/// /// [`Me`]: crate::types::Me /// [`Message`]: crate::types::Message /// diff --git a/src/dispatching/repls/repl.rs b/src/dispatching/repls/repl.rs index 1c6fd659..e0d52eae 100644 --- a/src/dispatching/repls/repl.rs +++ b/src/dispatching/repls/repl.rs @@ -30,6 +30,10 @@ use std::fmt::Debug; /// - `R` (type of the `bot`) /// - [`Me`] /// +/// Each of these types can be accepted as a handler parameter. Note that they +/// aren't all required at the same time: e.g., you can take only the bot and +/// the command without [`Me`] and [`Message`]. +/// /// [`Me`]: crate::types::Me /// [`Message`]: crate::types::Message /// @@ -78,6 +82,10 @@ where /// - `R` (type of the `bot`) /// - [`Me`] /// +/// Each of these types can be accepted as a handler parameter. Note that they +/// aren't all required at the same time: e.g., you can take only the bot and +/// the command without [`Me`] and [`Message`]. +/// /// [`Me`]: crate::types::Me /// [`Message`]: crate::types::Message /// From 8bfa8b542d24c2d84f8e84ad96ace7f498e7757e Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 7 Oct 2022 13:59:20 +0400 Subject: [PATCH 5/8] I hate rustfmt Former-commit-id: c6dd6bed441497e508ccd79b4071556447064916 --- src/dispatching/repls/commands_repl.rs | 4 ++++ src/dispatching/repls/repl.rs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/dispatching/repls/commands_repl.rs b/src/dispatching/repls/commands_repl.rs index b4f98866..d4e82954 100644 --- a/src/dispatching/repls/commands_repl.rs +++ b/src/dispatching/repls/commands_repl.rs @@ -12,6 +12,8 @@ use std::{fmt::Debug, marker::PhantomData}; /// A [REPL] for commands. // +/// +// #[doc = include_str!("preamble.md")] /// /// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop @@ -77,6 +79,8 @@ where /// A [REPL] for commands, with a custom [`UpdateListener`]. // +/// +// #[doc = include_str!("preamble.md")] /// /// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop diff --git a/src/dispatching/repls/repl.rs b/src/dispatching/repls/repl.rs index e0d52eae..e6fe69cb 100644 --- a/src/dispatching/repls/repl.rs +++ b/src/dispatching/repls/repl.rs @@ -9,6 +9,8 @@ use std::fmt::Debug; /// A [REPL] for messages. // +/// +// #[doc = include_str!("preamble.md")] /// /// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop @@ -58,6 +60,8 @@ where /// A [REPL] for messages, with a custom [`UpdateListener`]. // +/// +// #[doc = include_str!("preamble.md")] /// /// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop From 0daff74d14c31c6602e9178fc789b393b970c461 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 7 Oct 2022 14:06:42 +0400 Subject: [PATCH 6/8] fixups Former-commit-id: dc9ba4dd11c82bfc100eeee498f614a579a16d36 --- src/dispatching/repls/repl.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dispatching/repls/repl.rs b/src/dispatching/repls/repl.rs index e6fe69cb..fd26e6e2 100644 --- a/src/dispatching/repls/repl.rs +++ b/src/dispatching/repls/repl.rs @@ -34,7 +34,7 @@ use std::fmt::Debug; /// /// Each of these types can be accepted as a handler parameter. Note that they /// aren't all required at the same time: e.g., you can take only the bot and -/// the command without [`Me`] and [`Message`]. +/// the message without [`Me`]. /// /// [`Me`]: crate::types::Me /// [`Message`]: crate::types::Message @@ -88,7 +88,7 @@ where /// /// Each of these types can be accepted as a handler parameter. Note that they /// aren't all required at the same time: e.g., you can take only the bot and -/// the command without [`Me`] and [`Message`]. +/// the message without [`Me`]. /// /// [`Me`]: crate::types::Me /// [`Message`]: crate::types::Message From af5f27feee85467ed770122163d6baf706110069 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 7 Oct 2022 14:11:56 +0400 Subject: [PATCH 7/8] link "advanced features" in `repls` to `dispatching` Former-commit-id: 583e5ea4abeeb94456b1e1bb04c192d19ad89d8d --- src/dispatching/repls.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dispatching/repls.rs b/src/dispatching/repls.rs index 18fac935..71d70343 100644 --- a/src/dispatching/repls.rs +++ b/src/dispatching/repls.rs @@ -3,9 +3,10 @@ //! This module provides utilities for easy update handling. They accept a //! single "handler" function that processes all updates of a certain kind. Note //! that REPLs are meant to be used for simple scenarios, such as prototyping, -//! inasmuch they lack configuration and some advanced features. +//! inasmuch they lack configuration and some [advanced features]. //! //! [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop +//! [advanced features]: crate::dispatching#dispatching-or-repls mod commands_repl; mod repl; From 7ca26fbde12daa777071508a6e9b197a7742ac70 Mon Sep 17 00:00:00 2001 From: Waffle Maybe Date: Fri, 7 Oct 2022 14:22:02 +0400 Subject: [PATCH 8/8] Update src/dispatching/repls/preamble.md Co-authored-by: Hirrolot Former-commit-id: 1343015e6c5673a28f02882e810052ecad3bda71 --- src/dispatching/repls/preamble.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dispatching/repls/preamble.md b/src/dispatching/repls/preamble.md index 5c21f079..f434a325 100644 --- a/src/dispatching/repls/preamble.md +++ b/src/dispatching/repls/preamble.md @@ -4,4 +4,4 @@ See also: ["Dispatching or REPLs?"](dispatching/index.html#dispatching-or-repls) [`Dispatcher`]: crate::dispatching::Dispatcher -All errors from a the handler and will be logged. +All errors from the handler and update listener will be logged.