Improve type safety of write_list_flag function.

This commit is contained in:
Jeremy Wall 2018-03-17 09:15:13 -05:00
parent e6f2f12dc9
commit a7b214a9af

View File

@ -37,8 +37,13 @@ impl FlagConverter {
return Ok(());
}
fn write_list_flag(&self, pfx: &str, name: &str, v: &Val, w: &mut Write) -> Result<()> {
if let &Val::List(ref def) = v {
fn write_list_flag(
&self,
pfx: &str,
name: &str,
def: &Vec<Rc<Val>>,
w: &mut Write,
) -> Result<()> {
// first of all we need to make sure that each &Val is only a primitive type.
for v in def.iter() {
let vref = v.as_ref();
@ -52,9 +57,6 @@ impl FlagConverter {
try!(self.write(pfx, vref, w));
}
}
} else {
panic!("Impossible call happened. Somebody messed up.")
}
return Ok(());
}
@ -82,15 +84,19 @@ impl FlagConverter {
try!(self.write_flag_name(pfx, &name.val, w));
continue;
}
if val.is_tuple() {
match val.as_ref() {
&Val::Tuple(_) => {
let new_pfx = format!("{}{}.", pfx, name);
try!(self.write(&new_pfx, val, w));
} else if val.is_list() {
try!(self.write_list_flag(pfx, &name.val, &val, w));
} else {
}
&Val::List(ref def) => {
try!(self.write_list_flag(pfx, &name.val, def, w));
}
_ => {
try!(self.write_flag_name(pfx, &name.val, w));
try!(self.write(pfx, &val, w));
}
}
},
&Val::Macro(ref _def) => {
// This is ignored