libimagstore: Refactor code with is_match!() macro

This commit is contained in:
Matthias Beyer 2016-05-23 21:42:49 +02:00
parent e30d2480ab
commit b6f5b71df1
2 changed files with 7 additions and 13 deletions

View file

@ -128,15 +128,13 @@ pub fn config_is_valid(config: &Option<Value>) -> bool {
// The section "hooks" has maps which have a key "aspect" which has a value of type // The section "hooks" has maps which have a key "aspect" which has a value of type
// String // String
check_all_inner_maps_have_key_with(t, "hooks", "aspect", |asp| { check_all_inner_maps_have_key_with(t, "hooks", "aspect",
match *asp { Value::String(_) => true, _ => false } |asp| is_match!(asp, &Value::String(_))) &&
}) &&
// The section "aspects" has maps which have a key "parllel" which has a value of type // The section "aspects" has maps which have a key "parllel" which has a value of type
// Boolean // Boolean
check_all_inner_maps_have_key_with(t, "aspects", "parallel", |asp| { check_all_inner_maps_have_key_with(t, "aspects", "parallel",
match *asp { Value::Boolean(_) => true, _ => false, } |asp| is_match!(asp, &Value::Boolean(_)))
})
} }
_ => { _ => {
write!(stderr(), "Store config is no table").ok(); write!(stderr(), "Store config is no table").ok();

View file

@ -41,7 +41,7 @@ impl StoreIdAccessor for Aspect {
use crossbeam; use crossbeam;
let accessors : Vec<HDA> = self.hooks.iter().map(|h| h.accessor()).collect(); let accessors : Vec<HDA> = 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)); return Err(HE::new(HEK::AccessTypeViolation, None));
} }
@ -76,11 +76,7 @@ impl MutableHookDataAccessor for Aspect {
let accessors : Vec<HDA> = self.hooks.iter().map(|h| h.accessor()).collect(); let accessors : Vec<HDA> = self.hooks.iter().map(|h| h.accessor()).collect();
fn is_file_accessor(a: &HDA) -> bool { fn is_file_accessor(a: &HDA) -> bool {
match *a { is_match!(*a, HDA::MutableAccess(_) | HDA::NonMutableAccess(_))
HDA::MutableAccess(_) |
HDA::NonMutableAccess(_) => true,
_ => false,
}
} }
if !accessors.iter().all(|a| is_file_accessor(a)) { if !accessors.iter().all(|a| is_file_accessor(a)) {
@ -108,7 +104,7 @@ impl NonMutableHookDataAccessor for Aspect {
use crossbeam; use crossbeam;
let accessors : Vec<HDA> = self.hooks.iter().map(|h| h.accessor()).collect(); let accessors : Vec<HDA> = 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)); return Err(HE::new(HEK::AccessTypeViolation, None));
} }