From 14cd99f5f2099571bd989c771fd4fc6cd9208176 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 9 Jun 2016 19:31:12 +0200 Subject: [PATCH] Impl RefFlags::read() --- libimagref/src/flags.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/libimagref/src/flags.rs b/libimagref/src/flags.rs index 9d7a1a3b..1dbbbd3f 100644 --- a/libimagref/src/flags.rs +++ b/libimagref/src/flags.rs @@ -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 = and Value = boolean. pub fn read(v: &Value) -> Result { - unimplemented!() + fn get_field(v: &Value, key: &str) -> Result { + 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.