summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-02-27 12:50:14 +0100
committerGitHub <noreply@github.com>2017-02-27 12:50:14 +0100
commit85cb954b9fe907e9efc6d87744b0262f6f1960fc (patch)
treee59281858418f14af4780acb854b2fdea8b53423
parent84bcdc68b75188b818a6d384e02818ee2324cfba (diff)
parentc8faf5a6a9b0f0df92c20b413a8f428a5da55e4e (diff)
downloadimag-85cb954b9fe907e9efc6d87744b0262f6f1960fc.zip
imag-85cb954b9fe907e9efc6d87744b0262f6f1960fc.tar.gz
Merge pull request #909 from matthiasbeyer/less-fold-more-defresult
Less fold more defresult
-rw-r--r--libimagstore/src/configuration.rs55
1 files changed, 25 insertions, 30 deletions
diff --git a/libimagstore/src/configuration.rs b/libimagstore/src/configuration.rs
index eb9bd19..d8e08d4 100644
--- a/libimagstore/src/configuration.rs
+++ b/libimagstore/src/configuration.rs
@@ -20,6 +20,7 @@
use toml::Value;
use libimagerror::into::IntoError;
+use libimagutil::iter::FoldResult;
use store::Result;
@@ -86,15 +87,11 @@ pub fn config_is_valid(config: &Option<Value>) -> Result<()> {
})
.and_then(|t| match *t {
Value::Array(ref a) => {
- a.iter().fold(Ok(()), |acc, elem| {
- acc.and_then(|_| {
- if is_match!(*elem, Value::String(_)) {
- Ok(())
- } else {
- let cause = Box::new(kind.into_error());
- Err(SEK::ConfigTypeError.into_error_with_cause(cause))
- }
- })
+ a.iter().fold_defresult(|elem| if is_match!(*elem, Value::String(_)) {
+ Ok(())
+ } else {
+ let cause = Box::new(kind.into_error());
+ Err(SEK::ConfigTypeError.into_error_with_cause(cause))
})
},
_ => {
@@ -125,29 +122,27 @@ pub fn config_is_valid(config: &Option<Value>) -> Result<()> {
})
.and_then(|section_table| match *section_table { // which is
Value::Table(ref section_table) => // a table
- section_table.iter().fold(Ok(()), |acc, (inner_key, cfg)| {
- acc.and_then(|_| {
- match *cfg {
- Value::Table(ref hook_config) => { // are tables
- // with a key
- let hook_aspect_is_valid = try!(hook_config.get(key)
- .map(|hook_aspect| f(&hook_aspect))
- .ok_or(SEK::ConfigKeyMissingError.into_error())
- );
-
- if !hook_aspect_is_valid {
- Err(SEK::ConfigTypeError.into_error())
- } else {
- Ok(())
- }
- },
- _ => {
- warn!("Store config expects '{}' to be in '{}.{}', but isn't.",
- key, section, inner_key);
- Err(SEK::ConfigKeyMissingError.into_error())
+ section_table.iter().fold_defresult(|(inner_key, cfg)| {
+ match *cfg {
+ Value::Table(ref hook_config) => { // are tables
+ // with a key
+ let hook_aspect_is_valid = try!(hook_config.get(key)
+ .map(|hook_aspect| f(&hook_aspect))
+ .ok_or(SEK::ConfigKeyMissingError.into_error())
+ );
+
+ if !hook_aspect_is_valid {
+ Err(SEK::ConfigTypeError.into_error())
+ } else {
+ Ok(())
}
+ },
+ _ => {
+ warn!("Store config expects '{}' to be in '{}.{}', but isn't.",
+ key, section, inner_key);
+ Err(SEK::ConfigKeyMissingError.into_error())
}
- })
+ }
}),
_ => {
warn!("Store config expects '{}' to be a Table, but isn't.", section);