Minify impl of has_main_section()

This commit is contained in:
Matthias Beyer 2016-11-15 21:34:42 +01:00
parent 95105986b1
commit 58a42d127d
2 changed files with 5 additions and 10 deletions

View file

@ -1146,7 +1146,7 @@ mod test {
#[test] #[test]
fn test_imag_section() { fn test_imag_section() {
use super::has_main_section; use toml_ext::has_main_section;
let mut map = BTreeMap::new(); let mut map = BTreeMap::new();
map.insert("imag".into(), Value::Table(BTreeMap::new())); map.insert("imag".into(), Value::Table(BTreeMap::new()));
@ -1156,7 +1156,7 @@ mod test {
#[test] #[test]
fn test_imag_invalid_section_type() { fn test_imag_invalid_section_type() {
use super::has_main_section; use toml_ext::has_main_section;
let mut map = BTreeMap::new(); let mut map = BTreeMap::new();
map.insert("imag".into(), Value::Boolean(false)); map.insert("imag".into(), Value::Boolean(false));
@ -1166,7 +1166,7 @@ mod test {
#[test] #[test]
fn test_imag_abscent_main_section() { fn test_imag_abscent_main_section() {
use super::has_main_section; use toml_ext::has_main_section;
let mut map = BTreeMap::new(); let mut map = BTreeMap::new();
map.insert("not_imag".into(), Value::Boolean(false)); map.insert("not_imag".into(), Value::Boolean(false));

View file

@ -429,13 +429,8 @@ fn has_only_tables(t: &Table) -> bool {
t.iter().all(|(_, x)| is_match!(*x, Value::Table(_))) t.iter().all(|(_, x)| is_match!(*x, Value::Table(_)))
} }
fn has_main_section(t: &Table) -> bool { pub fn has_main_section(t: &Table) -> bool {
t.contains_key("imag") && t.contains_key("imag") && is_match!(t.get("imag"), Some(&Value::Table(_)))
match t.get("imag") {
Some(&Value::Table(_)) => true,
Some(_) => false,
None => false,
}
} }
fn has_imag_version_in_main_section(t: &Table) -> bool { fn has_imag_version_in_main_section(t: &Table) -> bool {