mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-22 03:12:27 +00:00
vmm: config: Consolidate on/off parsing
Now all parsing code makes use of the Toggle and it's FromStr support move the helper function into the from_str() implementation. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
c731a943d4
commit
a4e0ce58c7
@ -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<Self, Self::Err> {
|
||||
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<u64> {
|
||||
Ok(res << shift)
|
||||
}
|
||||
|
||||
fn parse_on_off(param: &str) -> Result<bool> {
|
||||
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user