mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +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:
+6
-19
@@ -53,8 +53,6 @@ pub enum Error {
|
|||||||
ParseVsockCidMissing,
|
ParseVsockCidMissing,
|
||||||
/// Missing kernel configuration
|
/// Missing kernel configuration
|
||||||
ValidateMissingKernelConfig,
|
ValidateMissingKernelConfig,
|
||||||
/// Failed parsing generic on|off parameter.
|
|
||||||
ParseOnOff,
|
|
||||||
/// Error parsing CPU options
|
/// Error parsing CPU options
|
||||||
ParseCpus(OptionParserError),
|
ParseCpus(OptionParserError),
|
||||||
/// Error parsing memory options
|
/// Error parsing memory options
|
||||||
@@ -252,9 +250,12 @@ impl FromStr for Toggle {
|
|||||||
type Err = ToggleParseError;
|
type Err = ToggleParseError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||||
Ok(Toggle(parse_on_off(s).map_err(|_| {
|
match s {
|
||||||
ToggleParseError::InvalidValue(s.to_owned())
|
"" => 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)
|
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)]
|
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
||||||
pub struct CpusConfig {
|
pub struct CpusConfig {
|
||||||
pub boot_vcpus: u8,
|
pub boot_vcpus: u8,
|
||||||
|
|||||||
Reference in New Issue
Block a user