From b6f5b71df1eca076f0b0be0c5a623d5cb122bccb Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 23 May 2016 21:42:49 +0200 Subject: [PATCH] libimagstore: Refactor code with is_match!() macro --- libimagstore/src/configuration.rs | 10 ++++------ libimagstore/src/hook/aspect.rs | 10 +++------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/libimagstore/src/configuration.rs b/libimagstore/src/configuration.rs index 6004a3d8..33e0a49e 100644 --- a/libimagstore/src/configuration.rs +++ b/libimagstore/src/configuration.rs @@ -128,15 +128,13 @@ pub fn config_is_valid(config: &Option) -> bool { // The section "hooks" has maps which have a key "aspect" which has a value of type // String - check_all_inner_maps_have_key_with(t, "hooks", "aspect", |asp| { - match *asp { Value::String(_) => true, _ => false } - }) && + check_all_inner_maps_have_key_with(t, "hooks", "aspect", + |asp| is_match!(asp, &Value::String(_))) && // The section "aspects" has maps which have a key "parllel" which has a value of type // Boolean - check_all_inner_maps_have_key_with(t, "aspects", "parallel", |asp| { - match *asp { Value::Boolean(_) => true, _ => false, } - }) + check_all_inner_maps_have_key_with(t, "aspects", "parallel", + |asp| is_match!(asp, &Value::Boolean(_))) } _ => { write!(stderr(), "Store config is no table").ok(); diff --git a/libimagstore/src/hook/aspect.rs b/libimagstore/src/hook/aspect.rs index f3d914e4..29d8c375 100644 --- a/libimagstore/src/hook/aspect.rs +++ b/libimagstore/src/hook/aspect.rs @@ -41,7 +41,7 @@ impl StoreIdAccessor for Aspect { use crossbeam; let accessors : Vec = self.hooks.iter().map(|h| h.accessor()).collect(); - if !accessors.iter().all(|a| match *a { HDA::StoreIdAccess(_) => true, _ => false }) { + if !accessors.iter().all(|a| is_match!(*a, HDA::StoreIdAccess(_))) { return Err(HE::new(HEK::AccessTypeViolation, None)); } @@ -76,11 +76,7 @@ impl MutableHookDataAccessor for Aspect { let accessors : Vec = self.hooks.iter().map(|h| h.accessor()).collect(); fn is_file_accessor(a: &HDA) -> bool { - match *a { - HDA::MutableAccess(_) | - HDA::NonMutableAccess(_) => true, - _ => false, - } + is_match!(*a, HDA::MutableAccess(_) | HDA::NonMutableAccess(_)) } if !accessors.iter().all(|a| is_file_accessor(a)) { @@ -108,7 +104,7 @@ impl NonMutableHookDataAccessor for Aspect { use crossbeam; let accessors : Vec = self.hooks.iter().map(|h| h.accessor()).collect(); - if !accessors.iter().all(|a| match *a { HDA::NonMutableAccess(_) => true, _ => false }) { + if !accessors.iter().all(|a| is_match!(*a, HDA::NonMutableAccess(_))) { return Err(HE::new(HEK::AccessTypeViolation, None)); }