Impl RefFlags::read()

This commit is contained in:
Matthias Beyer 2016-06-09 19:31:12 +02:00
parent 6a701d9646
commit 14cd99f5f2
1 changed files with 12 additions and 1 deletions

View File

@ -18,7 +18,18 @@ impl RefFlags {
/// Assumes that the whole TOML tree is passed. So this looks up `ref.flags` to get the flags.
/// It assumes that this is a Map with Key = <name of the setting> and Value = boolean.
pub fn read(v: &Value) -> Result<RefFlags> {
unimplemented!()
fn get_field(v: &Value, key: &str) -> Result<bool> {
match v.lookup(key) {
Some(&Value::Boolean(b)) => Ok(b),
Some(_) => Err(REK::HeaderTypeError.into()),
None => Err(REK::HeaderFieldMissingError.into()),
}
}
Ok(RefFlags {
content_hashing: try!(get_field(v, "ref.flags.content_hashing")),
permission_tracking: try!(get_field(v, "ref.flags.permission_tracking")),
})
}
/// Build a TOML::Value from this RefFlags object.