Merge pull request #400 from matthiasbeyer/libimagutil/match-helper
Libimagutil/match helper
This commit is contained in:
commit
41b5d6d230
10 changed files with 22 additions and 16 deletions
|
@ -17,3 +17,6 @@ path = "../libimagstore"
|
||||||
[dependencies.libimagerror]
|
[dependencies.libimagerror]
|
||||||
path = "../libimagerror"
|
path = "../libimagerror"
|
||||||
|
|
||||||
|
[dependencies.libimagutil]
|
||||||
|
path = "../libimagutil"
|
||||||
|
|
||||||
|
|
|
@ -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!("At least one of the Values which were expected in the Array of links is a non-String!");
|
||||||
debug!("Generating LinkError");
|
debug!("Generating LinkError");
|
||||||
return Err(LinkError::new(LinkErrorKind::ExistingLinkTypeWrong, None));
|
return Err(LinkError::new(LinkErrorKind::ExistingLinkTypeWrong, None));
|
||||||
|
|
|
@ -21,6 +21,7 @@ extern crate crypto;
|
||||||
|
|
||||||
#[macro_use] extern crate libimagstore;
|
#[macro_use] extern crate libimagstore;
|
||||||
#[macro_use] extern crate libimagerror;
|
#[macro_use] extern crate libimagerror;
|
||||||
|
#[macro_use] extern crate libimagutil;
|
||||||
|
|
||||||
module_entry_path_mod!("links", "0.1.0");
|
module_entry_path_mod!("links", "0.1.0");
|
||||||
|
|
||||||
|
|
|
@ -16,3 +16,6 @@ path = "../libimagstore"
|
||||||
[dependencies.libimagerror]
|
[dependencies.libimagerror]
|
||||||
path = "../libimagerror"
|
path = "../libimagerror"
|
||||||
|
|
||||||
|
[dependencies.libimagutil]
|
||||||
|
path = "../libimagutil"
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ extern crate toml;
|
||||||
|
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
#[macro_use] extern crate libimagerror;
|
#[macro_use] extern crate libimagerror;
|
||||||
|
#[macro_use] extern crate libimagutil;
|
||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod exec;
|
pub mod exec;
|
||||||
|
|
|
@ -37,7 +37,7 @@ impl Tagable for EntryHeader {
|
||||||
|
|
||||||
match tags {
|
match tags {
|
||||||
Some(Value::Array(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));
|
return Err(TagError::new(TagErrorKind::TagTypeError, None));
|
||||||
}
|
}
|
||||||
if tags.iter().any(|t| match *t {
|
if tags.iter().any(|t| match *t {
|
||||||
|
@ -110,7 +110,7 @@ impl Tagable for EntryHeader {
|
||||||
}
|
}
|
||||||
let tags = tags.unwrap();
|
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));
|
return Err(TagError::new(TagErrorKind::TagTypeError, None));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,9 @@ walkdir = "0.1.5"
|
||||||
[dependencies.libimagerror]
|
[dependencies.libimagerror]
|
||||||
path = "../libimagerror"
|
path = "../libimagerror"
|
||||||
|
|
||||||
|
[dependencies.libimagutil]
|
||||||
|
path = "../libimagutil"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempdir = "0.3.4"
|
tempdir = "0.3.4"
|
||||||
env_logger = "0.3"
|
env_logger = "0.3"
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ extern crate crossbeam;
|
||||||
extern crate walkdir;
|
extern crate walkdir;
|
||||||
|
|
||||||
#[macro_use] extern crate libimagerror;
|
#[macro_use] extern crate libimagerror;
|
||||||
|
#[macro_use] extern crate libimagutil;
|
||||||
|
|
||||||
pub mod storeid;
|
pub mod storeid;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
|
Loading…
Reference in a new issue