Merge pull request #131 from matthiasbeyer/libimagstore/entry-header-new-implicity
Dont pass the table to the header object, but generate it in ::new()
This commit is contained in:
commit
97816e7d2d
1 changed files with 30 additions and 8 deletions
|
@ -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<String, 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(version!()));
|
||||
imag_map.insert(String::from("links"), Value::Array(vec![]));
|
||||
|
||||
Value::Table(imag_map)
|
||||
});
|
||||
|
||||
m
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue