From 33f8d8cea1eb67fe9f73aad34891b85ccf37e4cc Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 16 Aug 2018 13:16:38 +0200 Subject: New `Map` struct; Rename existing `Map` struct to `MapAction` Add a new `Map` type that includes a field for `trigger`. This allows us to parse a single map definition line into a single struct, making parsing more granular than going directly to `MapCollection`. Rename the existing `Map` type to `MapAction` to support this change. --- src/lib.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index d10edd1..79941d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,11 +30,18 @@ pub enum MapKind { } #[derive(Debug)] -pub struct Map { +pub struct MapAction { pub action: Action, pub kind: MapKind, } -type MapCollection = HashMap; + +struct Map { + trigger: Trigger, + action: Action, + kind: MapKind, +} + +type MapCollection = HashMap; pub struct DKMapGroup { maps: MapCollection, @@ -118,7 +125,7 @@ where for (_, _, kind, _, trigger, _, action, _) in collection { maps.insert( trigger, - Map { + MapAction { action: action, kind: kind, } @@ -199,14 +206,14 @@ cmd /usr/bin/say 'hello' let mut expected = HashMap::new(); expected.insert( vec![HeadphoneButton::Up, HeadphoneButton::Down], - Map { + MapAction { action: "test".to_owned(), kind: MapKind::Map, }, ); expected.insert( vec![HeadphoneButton::Down], - Map { + MapAction { action: "/usr/bin/say 'hello'".to_owned(), kind: MapKind::Command, }, -- cgit v1.2.3