From c63783d2fa29b794fe5ee74fee6221073461f73a Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Fri, 13 Sep 2019 14:43:48 +0200 Subject: [PATCH] Refactor event manager to use dynamic dispatch --- src/event/manager.rs | 14 +++++++------- src/main.rs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/event/manager.rs b/src/event/manager.rs index b3f0471..a5e5706 100644 --- a/src/event/manager.rs +++ b/src/event/manager.rs @@ -5,15 +5,15 @@ pub trait EventManager { fn eventloop(&self); } -pub struct DefaultEventManager<'a, K: KeyEventReceiver, A: ActionEventReceiver> { +pub struct DefaultEventManager<'a> { receive_channel: Receiver, - key_receivers: Vec<&'a K>, - action_receivers: Vec<&'a A>, + key_receivers: Vec<&'a dyn KeyEventReceiver>, + action_receivers: Vec<&'a dyn ActionEventReceiver>, } -impl<'a, K: KeyEventReceiver, A: ActionEventReceiver> DefaultEventManager<'a, K, A> { - pub fn new(receive_channel: Receiver, key_receivers: Vec<&'a K>, - action_receivers: Vec<&'a A>) -> DefaultEventManager<'a, K, A> { +impl<'a> DefaultEventManager<'a> { + pub fn new(receive_channel: Receiver, key_receivers: Vec<&'a dyn KeyEventReceiver>, + action_receivers: Vec<&'a dyn ActionEventReceiver>) -> DefaultEventManager<'a> { DefaultEventManager { receive_channel, key_receivers, @@ -22,7 +22,7 @@ impl<'a, K: KeyEventReceiver, A: ActionEventReceiver> DefaultEventManager<'a, K, } } -impl <'a, K: KeyEventReceiver, A: ActionEventReceiver> EventManager for DefaultEventManager<'a, K, A> { +impl <'a> EventManager for DefaultEventManager<'a> { fn eventloop(&self) { loop { match self.receive_channel.recv() { diff --git a/src/main.rs b/src/main.rs index 75ababc..ffd5a73 100644 --- a/src/main.rs +++ b/src/main.rs @@ -121,7 +121,7 @@ fn espanso_background(receive_channel: Receiver, config_set: ConfigSet) { let event_manager = DefaultEventManager::new( receive_channel, vec!(&matcher), - vec!(&engine), + vec!(&engine, &matcher), ); event_manager.eventloop();