diff --git a/libimagstore/src/header.rs b/libimagstore/src/header.rs index 730798d2..dc432da2 100644 --- a/libimagstore/src/header.rs +++ b/libimagstore/src/header.rs @@ -1,7 +1,12 @@ +use std::collections::BTreeMap; use std::error::Error; use std::result::Result as RResult; -use toml::{Table, Value}; +use toml::{Array, Table, Value}; +use version; + +use self::error::ParserErrorKind; +use self::error::ParserError; pub mod error { use std::fmt::{Debug, Display, Formatter}; @@ -68,10 +73,6 @@ pub mod error { } - -use self::error::ParserErrorKind; -use self::error::ParserError; - /** * EntryHeader * @@ -92,10 +93,12 @@ impl EntryHeader { /** * Get a new header object with a already-filled toml table + * + * Default header values are inserted into the header object by default. */ - pub fn new(toml: Table) -> EntryHeader { + pub fn new() -> EntryHeader { EntryHeader { - toml: toml, + toml: build_default_header(), } } @@ -113,7 +116,11 @@ impl EntryHeader { parser.parse() .ok_or(ParserError::new(ParserErrorKind::TOMLParserErrors, None)) .and_then(|t| verify_header_consistency(t)) - .map(|t| EntryHeader::new(t)) + .map(|t| { + EntryHeader { + toml: t + } + }) } } @@ -283,3 +290,18 @@ mod test { } } +fn build_default_header() -> BTreeMap { + let mut m = BTreeMap::new(); + + m.insert(String::from("imag"), { + let mut imag_map = BTreeMap::::new(); + + imag_map.insert(String::from("version"), Value::String(version!())); + imag_map.insert(String::from("links"), Value::Array(vec![])); + + Value::Table(imag_map) + }); + + m +} +