From 796cd0134365ab5cabea062a238cb3adb35c4cbe Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 22 Jan 2016 08:28:28 +0100 Subject: [PATCH] Init the header with default values --- libimagstore/src/header.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/libimagstore/src/header.rs b/libimagstore/src/header.rs index 2c2ce652..dc432da2 100644 --- a/libimagstore/src/header.rs +++ b/libimagstore/src/header.rs @@ -2,7 +2,8 @@ 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; @@ -97,7 +98,7 @@ impl EntryHeader { */ pub fn new() -> EntryHeader { EntryHeader { - toml: BTreeMap::new(), + toml: build_default_header(), } } @@ -289,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 +} +