mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 21:55:20 +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:
parent
929142bc2e
commit
746138039d
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user