Merge pull request #400 from matthiasbeyer/libimagutil/match-helper

Libimagutil/match helper
This commit is contained in:
Matthias Beyer 2016-05-24 14:41:43 +02:00
commit 41b5d6d230
10 changed files with 22 additions and 16 deletions

View file

@ -17,3 +17,6 @@ path = "../libimagstore"
[dependencies.libimagerror]
path = "../libimagerror"
[dependencies.libimagutil]
path = "../libimagutil"

View file

@ -160,7 +160,7 @@ fn process_rw_result(links: StoreResult<Option<Value>>) -> Result<Vec<Link>> {
}
};
if !links.iter().all(|l| match *l { Value::String(_) => true, _ => false }) {
if !links.iter().all(|l| is_match!(*l, Value::String(_))) {
debug!("At least one of the Values which were expected in the Array of links is a non-String!");
debug!("Generating LinkError");
return Err(LinkError::new(LinkErrorKind::ExistingLinkTypeWrong, None));

View file

@ -21,6 +21,7 @@ extern crate crypto;
#[macro_use] extern crate libimagstore;
#[macro_use] extern crate libimagerror;
#[macro_use] extern crate libimagutil;
module_entry_path_mod!("links", "0.1.0");

View file

@ -16,3 +16,6 @@ path = "../libimagstore"
[dependencies.libimagerror]
path = "../libimagerror"
[dependencies.libimagutil]
path = "../libimagutil"

View file

@ -20,6 +20,7 @@ extern crate toml;
extern crate libimagstore;
#[macro_use] extern crate libimagerror;
#[macro_use] extern crate libimagutil;
pub mod error;
pub mod exec;

View file

@ -37,7 +37,7 @@ impl Tagable for EntryHeader {
match tags {
Some(Value::Array(tags)) => {
if !tags.iter().all(|t| match *t { Value::String(_) => true, _ => false }) {
if !tags.iter().all(|t| is_match!(*t, Value::String(_))) {
return Err(TagError::new(TagErrorKind::TagTypeError, None));
}
if tags.iter().any(|t| match *t {
@ -110,7 +110,7 @@ impl Tagable for EntryHeader {
}
let tags = tags.unwrap();
if !tags.iter().all(|t| match *t { Value::String(_) => true, _ => false }) {
if !tags.iter().all(|t| is_match!(*t, Value::String(_))) {
return Err(TagError::new(TagErrorKind::TagTypeError, None));
}

View file

@ -18,6 +18,9 @@ walkdir = "0.1.5"
[dependencies.libimagerror]
path = "../libimagerror"
[dependencies.libimagutil]
path = "../libimagutil"
[dev-dependencies]
tempdir = "0.3.4"
env_logger = "0.3"

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
// 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();

View file

@ -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));
}

View file

@ -25,6 +25,7 @@ extern crate crossbeam;
extern crate walkdir;
#[macro_use] extern crate libimagerror;
#[macro_use] extern crate libimagutil;
pub mod storeid;
pub mod error;