libimagstore: Refactor code with is_match!() macro
This commit is contained in:
parent
e30d2480ab
commit
b6f5b71df1
2 changed files with 7 additions and 13 deletions
|
@ -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
|
||||
// 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();
|
||||
|
|
|
@ -41,7 +41,7 @@ impl StoreIdAccessor for Aspect {
|
|||
use crossbeam;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -76,11 +76,7 @@ impl MutableHookDataAccessor for Aspect {
|
|||
let accessors : Vec<HDA> = 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<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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue