Use ::fold_defresult() instead of ::fold()
This commit is contained in:
parent
ef07c2cba9
commit
c8faf5a6a9
1 changed files with 24 additions and 29 deletions
|
@ -20,6 +20,7 @@
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
|
||||||
use libimagerror::into::IntoError;
|
use libimagerror::into::IntoError;
|
||||||
|
use libimagutil::iter::FoldResult;
|
||||||
|
|
||||||
use store::Result;
|
use store::Result;
|
||||||
|
|
||||||
|
@ -86,15 +87,11 @@ pub fn config_is_valid(config: &Option<Value>) -> Result<()> {
|
||||||
})
|
})
|
||||||
.and_then(|t| match *t {
|
.and_then(|t| match *t {
|
||||||
Value::Array(ref a) => {
|
Value::Array(ref a) => {
|
||||||
a.iter().fold(Ok(()), |acc, elem| {
|
a.iter().fold_defresult(|elem| if is_match!(*elem, Value::String(_)) {
|
||||||
acc.and_then(|_| {
|
|
||||||
if is_match!(*elem, Value::String(_)) {
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
let cause = Box::new(kind.into_error());
|
let cause = Box::new(kind.into_error());
|
||||||
Err(SEK::ConfigTypeError.into_error_with_cause(cause))
|
Err(SEK::ConfigTypeError.into_error_with_cause(cause))
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -125,8 +122,7 @@ pub fn config_is_valid(config: &Option<Value>) -> Result<()> {
|
||||||
})
|
})
|
||||||
.and_then(|section_table| match *section_table { // which is
|
.and_then(|section_table| match *section_table { // which is
|
||||||
Value::Table(ref section_table) => // a table
|
Value::Table(ref section_table) => // a table
|
||||||
section_table.iter().fold(Ok(()), |acc, (inner_key, cfg)| {
|
section_table.iter().fold_defresult(|(inner_key, cfg)| {
|
||||||
acc.and_then(|_| {
|
|
||||||
match *cfg {
|
match *cfg {
|
||||||
Value::Table(ref hook_config) => { // are tables
|
Value::Table(ref hook_config) => { // are tables
|
||||||
// with a key
|
// with a key
|
||||||
|
@ -147,7 +143,6 @@ pub fn config_is_valid(config: &Option<Value>) -> Result<()> {
|
||||||
Err(SEK::ConfigKeyMissingError.into_error())
|
Err(SEK::ConfigKeyMissingError.into_error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}),
|
}),
|
||||||
_ => {
|
_ => {
|
||||||
warn!("Store config expects '{}' to be a Table, but isn't.", section);
|
warn!("Store config expects '{}' to be a Table, but isn't.", section);
|
||||||
|
|
Loading…
Reference in a new issue