diff --git a/src/commands/set_master_pass.rs b/src/commands/set_master_pass.rs index e735c6a..0b6133e 100644 --- a/src/commands/set_master_pass.rs +++ b/src/commands/set_master_pass.rs @@ -7,14 +7,13 @@ async fn get_master_pass( msg: Message, db: DatabaseConnection, dialogue: MainDialogue, - master_password: String, + master_pass: String, ) -> crate::Result<()> { dialogue.exit().await?; let user_id = msg.from().ok_or(NoUserInfo)?.id.0; - let model = spawn_blocking(move || { - master_pass::ActiveModel::from_unencrypted(user_id, &master_password) - }) - .await?; + let model = + spawn_blocking(move || master_pass::ActiveModel::from_unencrypted(user_id, &master_pass)) + .await?; model.insert(&db).await?; bot.send_message(msg.chat.id, "Success") .reply_markup(deletion_markup()) @@ -41,7 +40,9 @@ pub async fn set_master_pass( .await?; dialogue .update(State::GetNewMasterPass(Handler::new( - get_master_pass, + |bot, msg, db, dialogue, master_pass| { + Box::pin(get_master_pass(bot, msg, db, dialogue, master_pass)) + }, &previous, ))) .await?; diff --git a/src/macros.rs b/src/macros.rs index bc213f4..155c2a3 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -12,7 +12,7 @@ macro_rules! handler { let previous = bot.send_message(msg.chat.id, $message).await?; dialogue .update($next_state(Handler::new( - move |bot, msg, db, dialogue, param| $next_func(bot, msg, db, dialogue, $($param,)* param), + move |bot, msg, db, dialogue, param| Box::pin($next_func(bot, msg, db, dialogue, $($param,)* param)), &previous, ))) .await?; @@ -45,7 +45,7 @@ macro_rules! ask_name_handler { .await?; dialogue .update(State::GetExistingName(Handler::new( - $next_func, + move |bot, msg, db, dialogue, param| Box::pin($next_func(bot, msg, db, dialogue, $($param,)* param)), &previous, ))) .await?; diff --git a/src/state/handler.rs b/src/state/handler.rs index 8b51efd..ab58e18 100644 --- a/src/state/handler.rs +++ b/src/state/handler.rs @@ -1,6 +1,6 @@ use crate::prelude::*; use futures::future::BoxFuture; -use std::{future::Future, sync::Arc}; +use std::sync::Arc; use teloxide::types::MessageId; use tokio::sync::Mutex; @@ -43,17 +43,20 @@ pub type PackagedHandler = Arc>>; impl Handler { /// Convinience method to convert a simple async function and a previous message into PackagedHandler #[inline] - pub fn new(f: H, previous: impl Into) -> PackagedHandler + pub fn new(f: H, previous: impl Into) -> PackagedHandler where - H: FnOnce(Throttle, Message, DatabaseConnection, MainDialogue, T) -> F + H: FnOnce( + Throttle, + Message, + DatabaseConnection, + MainDialogue, + T, + ) -> BoxFuture<'static, crate::Result<()>> + Send + 'static, - F: Future> + Send + 'static, { let handler = Self { - func: Some(Box::new(|bot, msg, db, dialogue, val| { - Box::pin(f(bot, msg, db, dialogue, val)) - })), + func: Some(Box::new(f)), previous: previous.into(), }; Arc::new(Mutex::new(handler))