diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 37be324a9..78fb77d6a 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -53,8 +53,6 @@ pub enum Error { ParseVsockCidMissing, /// Missing kernel configuration ValidateMissingKernelConfig, - /// Failed parsing generic on|off parameter. - ParseOnOff, /// Error parsing CPU options ParseCpus(OptionParserError), /// Error parsing memory options @@ -252,9 +250,12 @@ impl FromStr for Toggle { type Err = ToggleParseError; fn from_str(s: &str) -> std::result::Result { - Ok(Toggle(parse_on_off(s).map_err(|_| { - ToggleParseError::InvalidValue(s.to_owned()) - })?)) + match s { + "" => Ok(Toggle(false)), + "on" => Ok(Toggle(true)), + "off" => Ok(Toggle(false)), + _ => Err(ToggleParseError::InvalidValue(s.to_owned())), + } } } @@ -321,20 +322,6 @@ fn parse_size(size: &str) -> Result { Ok(res << shift) } -fn parse_on_off(param: &str) -> Result { - if !param.is_empty() { - let res = match param { - "on" => true, - "off" => false, - _ => return Err(Error::ParseOnOff), - }; - - Ok(res) - } else { - Ok(false) - } -} - #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct CpusConfig { pub boot_vcpus: u8,