diff --git a/src/dispatching/dispatcher.rs b/src/dispatching/dispatcher.rs index 7574fcc8..9e8a2e78 100644 --- a/src/dispatching/dispatcher.rs +++ b/src/dispatching/dispatcher.rs @@ -27,7 +27,7 @@ pub struct DispatcherBuilder { bot: R, dependencies: DependencyMap, handler: Arc>, - default_handler: Arc, + default_handler: DefaultHandler, error_handler: Arc + Send + Sync>, } @@ -48,10 +48,10 @@ where let handler = Arc::new(handler); Self { - default_handler: Arc::new(Box::new(move |upd| { + default_handler: Arc::new(move |upd| { let handler = Arc::clone(&handler); Box::pin(handler(upd)) - })), + }), ..self } } @@ -99,7 +99,7 @@ pub struct Dispatcher { dependencies: DependencyMap, handler: Arc>, - default_handler: Arc, + default_handler: DefaultHandler, // Tokio TX channel parts associated with chat IDs that consume updates sequentially. workers: HashMap, @@ -121,7 +121,7 @@ type WorkerTx = tokio::sync::mpsc::Sender; /// A handler that processes updates from Telegram. pub type UpdateHandler = dptree::Handler<'static, DependencyMap, Result<(), Err>>; -type DefaultHandler = Box) -> BoxFuture<'static, ()> + Send + Sync>; +type DefaultHandler = Arc) -> BoxFuture<'static, ()> + Send + Sync>; impl Dispatcher where @@ -138,10 +138,10 @@ where bot, dependencies: DependencyMap::new(), handler: Arc::new(handler), - default_handler: Arc::new(Box::new(|upd| { + default_handler: Arc::new(|upd| { log::warn!("Unhandled update: {:?}", upd); Box::pin(async {}) - })), + }), error_handler: LoggingErrorHandler::new(), } } @@ -307,7 +307,7 @@ const WORKER_QUEUE_SIZE: usize = 64; fn spawn_worker( deps: DependencyMap, handler: Arc>, - default_handler: Arc, + default_handler: DefaultHandler, error_handler: Arc + Send + Sync>, ) -> WorkerTx where @@ -338,7 +338,7 @@ where fn spawn_default_worker( deps: DependencyMap, handler: Arc>, - default_handler: Arc, + default_handler: DefaultHandler, error_handler: Arc + Send + Sync>, ) -> WorkerTx where @@ -370,7 +370,7 @@ async fn handle_update( update: Update, deps: Arc, handler: Arc>, - default_handler: Arc, + default_handler: DefaultHandler, error_handler: Arc + Send + Sync>, ) where Err: Send + Sync + 'static,