Update rust, direnv-nix

This commit is contained in:
Sam W 2022-07-08 13:23:05 +01:00
parent c3361915a4
commit d4a0a1e992
4 changed files with 46 additions and 18 deletions

4
.envrc
View File

@ -1 +1,5 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.1.1; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.1.1/direnvrc" "sha256-b6qJ4r34rbE23yWjMqbmu3ia2z4b2wIlZUksBke/ol0="
fi
use flake
export RUST_LOG=info

View File

@ -36,11 +36,11 @@
},
"flake-utils_2": {
"locked": {
"lastModified": 1637014545,
"narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=",
"lastModified": 1656065134,
"narHash": "sha256-oc6E6ByIw3oJaIyc67maaFcnjYOz1mMcOtHxbEf9NwQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4",
"rev": "bee6a7250dd1b01844a2de7e02e4df7d8a0a206c",
"type": "github"
},
"original": {
@ -113,11 +113,11 @@
},
"nixpkgs_4": {
"locked": {
"lastModified": 1637453606,
"narHash": "sha256-Gy6cwUswft9xqsjWxFYEnx/63/qzaFUwatcbV5GF/GQ=",
"lastModified": 1656401090,
"narHash": "sha256-bUS2nfQsvTQW2z8SK7oEFSElbmoBahOPtbXPm0AL3I4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "8afc4e543663ca0a6a4f496262cd05233737e732",
"rev": "16de63fcc54e88b9a106a603038dd5dd2feb21eb",
"type": "github"
},
"original": {
@ -142,11 +142,11 @@
"nixpkgs": "nixpkgs_4"
},
"locked": {
"lastModified": 1652064227,
"narHash": "sha256-ZpIfELJNVzcxa6+YUr1KfbpTkHh02FASdlHaCC5/Q6w=",
"lastModified": 1657248581,
"narHash": "sha256-VSAhHCruQCFWzTz7ZSW5QLb2xIKrBGeEyEfKds4MXeY=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "31db726b18ad2620fead6e7cd31b6e57d1cd061b",
"rev": "6bd9919005ab6bf72464c9ebdd80f89b0cf82f97",
"type": "github"
},
"original": {

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)]

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"),
}
}