Fix libimagref for toml 0.4

This commit is contained in:
Matthias Beyer 2017-05-03 20:27:21 +02:00
parent c1596d9c61
commit da01875e9f
2 changed files with 11 additions and 5 deletions

View file

@ -24,6 +24,7 @@ generate_error_module!(
IOError => "IO Error",
UTF8Error => "UTF8 Error",
StoreIdError => "Error with storeid",
HeaderTomlError => "Error while working with TOML Header",
HeaderTypeError => "Header type error",
HeaderFieldMissingError => "Header field missing error",
HeaderFieldWriteError => "Header field cannot be written",

View file

@ -37,11 +37,16 @@ impl RefFlags {
/// It assumes that this is a Map with Key = <name of the setting> and Value = boolean.
pub fn read(v: &Value) -> Result<RefFlags> {
fn get_field(v: &Value, key: &str) -> Result<bool> {
match v.lookup(key) {
Some(&Value::Boolean(b)) => Ok(b),
use libimagstore::toml_ext::TomlValueExt;
use error::MapErrInto;
v.read(key)
.map_err_into(REK::HeaderTomlError)
.and_then(|toml| match toml {
Some(Value::Boolean(b)) => Ok(b),
Some(_) => Err(REK::HeaderTypeError.into()),
None => Err(REK::HeaderFieldMissingError.into()),
}
})
}
Ok(RefFlags {