Update rust, direnv-nix

This commit is contained in:
2022-07-08 13:43:17 +01:00
parent c3361915a4
commit d4a0a1e992
4 changed files with 46 additions and 18 deletions
+28 -4
View File
@@ -24,12 +24,36 @@ impl fmt::Display for Action {
}
}
#[derive(Deserialize, StaticType, Debug)]
pub struct Actions(Vec<Action>);
impl fmt::Display for Actions {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Actions(count={})", self.0.len())
}
}
#[derive(Deserialize, StaticType, Debug)]
pub enum Mapping {
NOP, // Do nothing.
Passthrough, // Passthrough to the layer below
Trigger(Action), // Trigger an action
TriggerMulti(Vec<Action>), // Trigger multiple actions in sequence
NOP, // Do nothing.
Passthrough, // Passthrough to the layer below
Trigger(Action), // Trigger an action
TriggerMulti(Actions), // Trigger multiple actions in sequence
}
impl fmt::Display for Mapping {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
match &self {
Mapping::NOP => "NOP".to_owned(),
Mapping::Passthrough => "Passthrough".to_owned(),
Mapping::Trigger(act) => format!("Trigger({})", act),
Mapping::TriggerMulti(acts) => format!("Trigger({})", acts),
},
)
}
}
#[derive(Deserialize, Debug)]
+5 -5
View File
@@ -1,7 +1,7 @@
mod config;
mod device;
use config::{Action, Config};
use config::{Action, Config, Mapping};
use hidapi::HidApi;
use rumqttc::{Client, MqttOptions, QoS};
use std::collections::HashMap;
@@ -88,10 +88,10 @@ impl<'a> State<'a> {
}
}
fn execute_mapping(&mut self, m: &config::Mapping) {
match m {
config::Mapping::Trigger(t) => self.execute_action(t),
_ => {}
fn execute_mapping(&mut self, mapping: &Mapping) {
match mapping {
Mapping::Trigger(t) => self.execute_action(t),
_ => event!(Level::WARN, %mapping, "Ignoring unimplemented mapping"),
}
}