diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2018-06-08 01:59:03 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2018-07-19 20:58:27 +0200 |
commit | 9ad1c8d6bdca933732228ce1359bfab769c20c4d (patch) | |
tree | b81577ac81c3bb43699d32d5143685038b12b14f /lib | |
parent | 1705ecbbff3c42d3072f7d9136ef04c17e863ec0 (diff) |
Simplify: Move default header generation from Value extension to Entry type
Diffstat (limited to 'lib')
-rw-r--r-- | lib/core/libimagstore/src/store.rs | 39 |
1 files changed, 12 insertions, 27 deletions
diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index 4b92ac56..92fabc47 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -766,7 +766,18 @@ impl Entry { /// This function should be used to get a new Header, as the default header may change. Via /// this function, compatibility is ensured. pub fn default_header() -> Value { // BTreeMap<String, Value> - Value::default_header() + let mut m = BTreeMap::new(); + + m.insert(String::from("imag"), { + let mut imag_map = BTreeMap::<String, Value>::new(); + + imag_map.insert(String::from("version"), + Value::String(String::from(env!("CARGO_PKG_VERSION")))); + + Value::Table(imag_map) + }); + + Value::Table(m) } /// See `Entry::from_str()`, as this function is used internally. This is just a wrapper for @@ -873,22 +884,11 @@ impl PartialEq for Entry { pub trait Header { fn verify(&self) -> Result<()>; fn parse(s: &str) -> Result<Value>; - fn default_header() -> Value; } impl Header for Value { fn verify(&self) -> Result<()> { - if !has_main_section(self)? { - Err(SE::from_kind(SEK::MissingMainSection)) - } else if !has_imag_version_in_main_section(self)? { - Err(SE::from_kind(SEK::MissingVersionInfo)) - } else if !has_only_tables(self)? { - debug!("Could not verify that it only has tables in its base table"); - Err(SE::from_kind(SEK::NonTableInBaseTable)) - } else { - Ok(()) - } } fn parse(s: &str) -> Result<Value> { @@ -899,21 +899,6 @@ impl Header for Value { .and_then(|h: Value| h.verify().map(|_| h)) } - fn default_header() -> Value { - let mut m = BTreeMap::new(); - - m.insert(String::from("imag"), { - let mut imag_map = BTreeMap::<String, Value>::new(); - - imag_map.insert(String::from("version"), - Value::String(String::from(env!("CARGO_PKG_VERSION")))); - - Value::Table(imag_map) - }); - - Value::Table(m) - } - } fn has_only_tables(t: &Value) -> Result<bool> { |