From 746138039d124b80e80c6ec072d7bc43d6c0df19 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 27 Mar 2020 12:33:32 +0000 Subject: [PATCH] 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 --- vmm/src/config.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index c93ba691f..045276357 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -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 { + Ok(Toggle(parse_on_off(s).map_err(|_| { + ToggleParseError::InvalidValue(s.to_owned()) + })?)) + } +} + fn parse_size(size: &str) -> Result { let s = size.trim();