mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
@@ -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> {
|
fn parse_size(size: &str) -> Result<u64> {
|
||||||
let s = size.trim();
|
let s = size.trim();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user