Refactor event manager to use dynamic dispatch
This commit is contained in:
parent
2a60a87f3d
commit
c63783d2fa
src
|
@ -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<Event>,
|
||||
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<Event>, key_receivers: Vec<&'a K>,
|
||||
action_receivers: Vec<&'a A>) -> DefaultEventManager<'a, K, A> {
|
||||
impl<'a> DefaultEventManager<'a> {
|
||||
pub fn new(receive_channel: Receiver<Event>, 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() {
|
||||
|
|
|
@ -121,7 +121,7 @@ fn espanso_background(receive_channel: Receiver<Event>, config_set: ConfigSet) {
|
|||
let event_manager = DefaultEventManager::new(
|
||||
receive_channel,
|
||||
vec!(&matcher),
|
||||
vec!(&engine),
|
||||
vec!(&engine, &matcher),
|
||||
);
|
||||
|
||||
event_manager.eventloop();
|
||||
|
|
Loading…
Reference in New Issue
Block a user