From 8d858c43ff2ac27ca34a7e6063750b997d39a432 Mon Sep 17 00:00:00 2001 From: jrx Date: Thu, 31 Aug 2023 23:03:54 +0200 Subject: [PATCH] revert tryable repls --- crates/teloxide/src/lib.rs | 2 +- crates/teloxide/src/repls.rs | 2 +- crates/teloxide/src/repls/repl.rs | 122 +----------------------------- 3 files changed, 6 insertions(+), 120 deletions(-) diff --git a/crates/teloxide/src/lib.rs b/crates/teloxide/src/lib.rs index d5bb39ca..1a1c6797 100644 --- a/crates/teloxide/src/lib.rs +++ b/crates/teloxide/src/lib.rs @@ -60,7 +60,7 @@ #![allow(clippy::nonstandard_macro_braces)] #[cfg(feature = "ctrlc_handler")] -pub use repls::{repl, repl_with_listener, try_repl, try_repl_with_listener}; +pub use repls::{repl, repl_with_listener}; #[cfg(feature = "ctrlc_handler")] #[allow(deprecated)] diff --git a/crates/teloxide/src/repls.rs b/crates/teloxide/src/repls.rs index 96df9dfa..aea4806e 100644 --- a/crates/teloxide/src/repls.rs +++ b/crates/teloxide/src/repls.rs @@ -14,4 +14,4 @@ mod repl; pub use commands_repl::CommandReplExt; #[allow(deprecated)] pub use commands_repl::{commands_repl, commands_repl_with_listener}; -pub use repl::{repl, repl_with_listener, try_repl, try_repl_with_listener}; +pub use repl::{repl, repl_with_listener}; diff --git a/crates/teloxide/src/repls/repl.rs b/crates/teloxide/src/repls/repl.rs index 23bde903..636802a4 100644 --- a/crates/teloxide/src/repls/repl.rs +++ b/crates/teloxide/src/repls/repl.rs @@ -50,65 +50,13 @@ use std::fmt::Debug; /// #[cfg(feature = "ctrlc_handler")] pub async fn repl(bot: R, handler: H) -where - R: Requester + Send + Sync + Clone + 'static, - ::GetUpdates: Send, - H: Injectable, Args> + Send + Sync + 'static, -{ - try_repl(bot, handler).await.expect("try_repl failed") -} - -/// Same as `repl` but returns a Result<_> instead of panicking -/// -/// A [REPL] for messages. -// -/// -// -#[doc = include_str!("preamble.md")] -/// -/// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop -/// -/// ## 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. 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 -/// -/// `teloxide` provides the following types to the `handler`: -/// - [`Message`] -/// - `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 message without [`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 try_repl(bot: R, handler: H) -> Result<(), R::Err> where R: Requester + Send + Sync + Clone + 'static, ::GetUpdates: Send, H: Injectable, Args> + Send + Sync + 'static, { let cloned_bot = bot.clone(); - try_repl_with_listener(bot, handler, update_listeners::polling_default(cloned_bot).await).await + repl_with_listener(bot, handler, update_listeners::polling_default(cloned_bot).await).await; } /// A [REPL] for messages, with a custom [`UpdateListener`]. @@ -156,66 +104,6 @@ where /// #[cfg(feature = "ctrlc_handler")] 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, - L: UpdateListener + Send, - L::Err: Debug, -{ - try_repl_with_listener(bot, handler, listener).await.expect("try_repl_with_listener failed") -} - -/// Same as `repl_with_listener` but returns a Result<_> instead of panicking -/// -/// A [REPL] for messages, with a custom [`UpdateListener`]. -// -/// -// -#[doc = include_str!("preamble.md")] -/// -/// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop -/// [`UpdateListener`]: crate::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. 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 -/// -/// `teloxide` provides the following types to the `handler`: -/// - [`Message`] -/// - `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 message without [`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 try_repl_with_listener( - bot: R, - handler: H, - listener: L, -) -> Result<(), R::Err> where R: Requester + Clone + Send + Sync + 'static, H: Injectable, Args> + Send + Sync + 'static, @@ -232,13 +120,11 @@ where .default_handler(ignore_update) .enable_ctrlc_handler() .build() - .try_dispatch_with_listener( + .dispatch_with_listener( listener, LoggingErrorHandler::with_custom_text("An error from the update listener"), ) - .await?; - - Ok(()) + .await; } #[test] @@ -248,4 +134,4 @@ fn repl_is_send() { assert_send(&repl); fn assert_send(_: &impl Send) {} -} +} \ No newline at end of file