Move header verifying into helper function
This commit is contained in:
parent
2a4f3baf0b
commit
9884f78dae
1 changed files with 12 additions and 10 deletions
|
@ -112,20 +112,22 @@ impl EntryHeader {
|
||||||
let mut parser = Parser::new(s);
|
let mut parser = Parser::new(s);
|
||||||
parser.parse()
|
parser.parse()
|
||||||
.ok_or(ParserError::new(ParserErrorKind::TOMLParserErrors, None))
|
.ok_or(ParserError::new(ParserErrorKind::TOMLParserErrors, None))
|
||||||
.and_then(|table| {
|
.and_then(|t| verify_header_consistency(t))
|
||||||
if !has_main_section(&table) {
|
.map(|t| EntryHeader::new(t))
|
||||||
Err(ParserError::new(ParserErrorKind::MissingMainSection, None))
|
|
||||||
} else if !has_imag_version_in_main_section(&table) {
|
|
||||||
Err(ParserError::new(ParserErrorKind::MissingVersionInfo, None))
|
|
||||||
} else {
|
|
||||||
Ok(table)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.map(|table| EntryHeader::new(table))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn verify_header_consistency(t: Table) -> Result<Table> {
|
||||||
|
if !has_main_section(&t) {
|
||||||
|
Err(ParserError::new(ParserErrorKind::MissingMainSection, None))
|
||||||
|
} else if !has_imag_version_in_main_section(&t) {
|
||||||
|
Err(ParserError::new(ParserErrorKind::MissingVersionInfo, None))
|
||||||
|
} else {
|
||||||
|
Ok(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn has_main_section(t: &Table) -> bool {
|
fn has_main_section(t: &Table) -> bool {
|
||||||
t.contains_key("imag") &&
|
t.contains_key("imag") &&
|
||||||
match t.get("imag") {
|
match t.get("imag") {
|
||||||
|
|
Loading…
Reference in a new issue