Refactor event manager to use dynamic dispatch

This commit is contained in:
Federico Terzi 2019-09-13 14:43:48 +02:00
parent 2a60a87f3d
commit c63783d2fa
2 changed files with 8 additions and 8 deletions

View File

@ -5,15 +5,15 @@ pub trait EventManager {
fn eventloop(&self); fn eventloop(&self);
} }
pub struct DefaultEventManager<'a, K: KeyEventReceiver, A: ActionEventReceiver> { pub struct DefaultEventManager<'a> {
receive_channel: Receiver<Event>, receive_channel: Receiver<Event>,
key_receivers: Vec<&'a K>, key_receivers: Vec<&'a dyn KeyEventReceiver>,
action_receivers: Vec<&'a A>, action_receivers: Vec<&'a dyn ActionEventReceiver>,
} }
impl<'a, K: KeyEventReceiver, A: ActionEventReceiver> DefaultEventManager<'a, K, A> { impl<'a> DefaultEventManager<'a> {
pub fn new(receive_channel: Receiver<Event>, key_receivers: Vec<&'a K>, pub fn new(receive_channel: Receiver<Event>, key_receivers: Vec<&'a dyn KeyEventReceiver>,
action_receivers: Vec<&'a A>) -> DefaultEventManager<'a, K, A> { action_receivers: Vec<&'a dyn ActionEventReceiver>) -> DefaultEventManager<'a> {
DefaultEventManager { DefaultEventManager {
receive_channel, receive_channel,
key_receivers, 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) { fn eventloop(&self) {
loop { loop {
match self.receive_channel.recv() { match self.receive_channel.recv() {

View File

@ -121,7 +121,7 @@ fn espanso_background(receive_channel: Receiver<Event>, config_set: ConfigSet) {
let event_manager = DefaultEventManager::new( let event_manager = DefaultEventManager::new(
receive_channel, receive_channel,
vec!(&matcher), vec!(&matcher),
vec!(&engine), vec!(&engine, &matcher),
); );
event_manager.eventloop(); event_manager.eventloop();