From 14e98606970f4c3d338a9541cb180aed35893227 Mon Sep 17 00:00:00 2001 From: Sam Willcocks Date: Fri, 8 Jul 2022 14:01:09 +0100 Subject: [PATCH] Support triggering multiple actions --- src/config.rs | 7 +++++++ src/main.rs | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 05edec9..b3f99cd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,6 +27,13 @@ impl fmt::Display for Action { #[derive(Deserialize, StaticType, Debug)] pub struct Actions(Vec); +impl Actions { + // Return the iterator over the inner Vec of Actions + pub fn iter(&self) -> std::slice::Iter { + self.0.iter() + } +} + impl fmt::Display for Actions { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "Actions(count={})", self.0.len()) diff --git a/src/main.rs b/src/main.rs index b8f907c..ac67286 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,7 +90,8 @@ impl<'a> State<'a> { fn execute_mapping(&mut self, mapping: &Mapping) { match mapping { - Mapping::Trigger(t) => self.execute_action(t), + Mapping::Trigger(act) => self.execute_action(act), + Mapping::TriggerMulti(acts) => acts.iter().map(|a| self.execute_action(a)).collect(), _ => event!(Level::WARN, %mapping, "Ignoring unimplemented mapping"), } }