diff --git a/src/dispatching/dispatcher.rs b/src/dispatching/dispatcher.rs index 49068405..fb478adf 100644 --- a/src/dispatching/dispatcher.rs +++ b/src/dispatching/dispatcher.rs @@ -107,6 +107,7 @@ where /// [`shutdown`]: ShutdownToken::shutdown #[cfg(feature = "ctrlc_handler")] #[cfg_attr(all(docsrs, feature = "nightly"), doc(cfg(feature = "ctrlc_handler")))] + #[must_use] pub fn setup_ctrlc_handler(self) -> Self { let state = Arc::clone(&self.state); tokio::spawn(async move { diff --git a/src/dispatching2/dialogue/dialogue_handler_ext.rs b/src/dispatching2/dialogue/dialogue_handler_ext.rs index d529075f..617ce021 100644 --- a/src/dispatching2/dialogue/dialogue_handler_ext.rs +++ b/src/dispatching2/dialogue/dialogue_handler_ext.rs @@ -3,6 +3,7 @@ use dptree::{di::DependencyMap, Handler}; use std::sync::Arc; pub trait DialogueHandlerExt { + #[must_use] fn add_dialogue<Upd, S, D>(self) -> Self where S: Storage<D> + Send + Sync + 'static, diff --git a/src/dispatching2/dialogue/mod.rs b/src/dispatching2/dialogue/mod.rs index 81fce4d2..1da20844 100644 --- a/src/dispatching2/dialogue/mod.rs +++ b/src/dispatching2/dialogue/mod.rs @@ -28,11 +28,7 @@ pub struct Dialogue<D, S> { // but `S` wrapped around Arc, and `D` wrapped around PhantomData. impl<D, S> Clone for Dialogue<D, S> { fn clone(&self) -> Self { - Dialogue { - storage: self.storage.clone(), - chat_id: self.chat_id.clone(), - _phantom: PhantomData, - } + Dialogue { storage: self.storage.clone(), chat_id: self.chat_id, _phantom: PhantomData } } } diff --git a/src/dispatching2/dispatcher.rs b/src/dispatching2/dispatcher.rs index def5bed1..553f090d 100644 --- a/src/dispatching2/dispatcher.rs +++ b/src/dispatching2/dispatcher.rs @@ -65,6 +65,7 @@ where /// [`shutdown`]: ShutdownToken::shutdown #[cfg(feature = "ctrlc_handler")] #[cfg_attr(docsrs, doc(cfg(feature = "ctrlc_handler")))] + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn setup_ctrlc_handler(self) -> Self { let state = Arc::clone(&self.state); tokio::spawn(async move { @@ -227,21 +228,25 @@ where } } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn handler(self, handler: UpdateHandler<Err>) -> Self { Dispatcher { handler: self.handler.branch(handler), ..self } } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] // Specify handler that will be called if other handlers was not handle the // update. pub fn default_handler(self, handler: UpdateHandler<Err>) -> Self { Dispatcher { handler: self.handler.branch(handler), ..self } } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] // Specify dependencies that can be used inside of handlers. pub fn dependencies(self, dependencies: DependencyMap) -> Self { Dispatcher { dependencies, ..self } } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn messages_handler( mut self, make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>, @@ -253,6 +258,7 @@ where self.handler(handler) } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn edited_messages_handler( mut self, make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>, @@ -264,6 +270,7 @@ where self.handler(handler) } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn channel_posts_handler( mut self, make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>, @@ -275,6 +282,7 @@ where self.handler(handler) } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn edited_channel_posts_handler( mut self, make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>, @@ -286,6 +294,7 @@ where self.handler(handler) } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn inline_queries_handler( mut self, make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>, @@ -297,6 +306,7 @@ where self.handler(handler) } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn chosen_inline_results_handler( mut self, make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>, @@ -308,6 +318,7 @@ where self.handler(handler) } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn callback_queries_handler( mut self, make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>, @@ -319,6 +330,7 @@ where self.handler(handler) } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn shipping_queries_handler( mut self, make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>, @@ -330,6 +342,7 @@ where self.handler(handler) } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn pre_checkout_queries_handler( mut self, make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>, @@ -341,6 +354,7 @@ where self.handler(handler) } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn polls_handler( mut self, make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>, @@ -352,6 +366,7 @@ where self.handler(handler) } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn poll_answers_handler( mut self, make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>, @@ -363,6 +378,7 @@ where self.handler(handler) } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn my_chat_members_handler( mut self, make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>, @@ -374,6 +390,7 @@ where self.handler(handler) } + #[must_use = "Call .dispatch() or .dispatch_with_listener() function to start dispatching."] pub fn chat_members_handler( mut self, make_handler: impl FnOnce(UpdateHandler<Err>) -> UpdateHandler<Err>, diff --git a/src/dispatching2/handler_ext.rs b/src/dispatching2/handler_ext.rs index 873c8aa9..fb9d912b 100644 --- a/src/dispatching2/handler_ext.rs +++ b/src/dispatching2/handler_ext.rs @@ -2,10 +2,12 @@ use crate::{dispatching2::HandlerFactory, types::Message, utils::command::BotCom use dptree::{di::DependencyMap, Handler}; pub trait HandlerExt<Output> { + #[must_use] fn add_command<C>(self, bot_name: String) -> Self where C: BotCommand + Send + Sync + 'static; + #[must_use] fn dispatch_by<F>(self) -> Self where F: HandlerFactory<Out = Output>; diff --git a/src/utils/html.rs b/src/utils/html.rs index dc26a299..d61c84c2 100644 --- a/src/utils/html.rs +++ b/src/utils/html.rs @@ -61,7 +61,7 @@ pub fn code_block(code: &str) -> String { pub fn code_block_with_lang(code: &str, lang: &str) -> String { format!( "<pre><code class=\"language-{}\">{}</code></pre>", - escape(lang).replace("\"", """), + escape(lang).replace('"', """), escape(code) ) } @@ -81,7 +81,7 @@ pub fn code_inline(s: &str) -> String { /// /// [spec]: https://core.telegram.org/bots/api#html-style pub fn escape(s: &str) -> String { - s.replace("&", "&").replace("<", "<").replace(">", ">") + s.replace('&', "&").replace('<', "<").replace('>', ">") } pub fn user_mention_or_link(user: &User) -> String { diff --git a/src/utils/markdown.rs b/src/utils/markdown.rs index d778aee2..6ee5f451 100644 --- a/src/utils/markdown.rs +++ b/src/utils/markdown.rs @@ -89,36 +89,36 @@ pub fn code_inline(s: &str) -> String { /// /// [spec]: https://core.telegram.org/bots/api#html-style pub fn escape(s: &str) -> String { - s.replace("_", r"\_") - .replace("*", r"\*") - .replace("[", r"\[") - .replace("]", r"\]") - .replace("(", r"\(") - .replace(")", r"\)") - .replace("~", r"\~") - .replace("`", r"\`") - .replace(">", r"\>") - .replace("#", r"\#") - .replace("+", r"\+") - .replace("-", r"\-") - .replace("=", r"\=") - .replace("|", r"\|") - .replace("{", r"\{") - .replace("}", r"\}") - .replace(".", r"\.") - .replace("!", r"\!") + s.replace('_', r"\_") + .replace('*', r"\*") + .replace('[', r"\[") + .replace(']', r"\]") + .replace('(', r"\(") + .replace(')', r"\)") + .replace('~', r"\~") + .replace('`', r"\`") + .replace('>', r"\>") + .replace('#', r"\#") + .replace('+', r"\+") + .replace('-', r"\-") + .replace('=', r"\=") + .replace('|', r"\|") + .replace('{', r"\{") + .replace('}', r"\}") + .replace('.', r"\.") + .replace('!', r"\!") } /// Escapes all markdown special characters specific for the inline link URL /// (``` and `)`). pub fn escape_link_url(s: &str) -> String { - s.replace("`", r"\`").replace(")", r"\)") + s.replace('`', r"\`").replace(')', r"\)") } /// Escapes all markdown special characters specific for the code block (``` and /// `\`). pub fn escape_code(s: &str) -> String { - s.replace(r"\", r"\\").replace("`", r"\`") + s.replace('\\', r"\\").replace('`', r"\`") } pub fn user_mention_or_link(user: &User) -> String {