vmm: config: Add a Toggle type for "on/off" strings

Some of the config parameters take an "on" or "off". Add a way to
neatly parse that.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-03-27 12:33:32 +00:00
parent 929142bc2e
commit 746138039d

View File

@ -246,6 +246,22 @@ impl<'a> VmParams<'a> {
}
}
struct Toggle(bool);
enum ToggleParseError {
InvalidValue(String),
}
impl FromStr for Toggle {
type Err = ToggleParseError;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
Ok(Toggle(parse_on_off(s).map_err(|_| {
ToggleParseError::InvalidValue(s.to_owned())
})?))
}
}
fn parse_size(size: &str) -> Result<u64> {
let s = size.trim();