MCPcopy Index your code
hub / github.com/cloud-hypervisor/cloud-hypervisor / convert

Method convert

option_parser/src/lib.rs:275–288  ·  view source on GitHub ↗

Retrieves and converts an option value to type `T`. Returns `Ok(None)` if the option was not set or its value is empty. Returns `Err` if the value cannot be converted to `T`. `T` can be any type that implements `FromStr` (e.g. `u32`, `String`), or one of this crate's types such as [`Toggle`], [`IntegerList`], [`Tuple`], or [`StringList`].

(&self, option: &str)

Source from the content-addressed store, hash-verified

273 /// or one of this crate's types such as [`Toggle`], [`IntegerList`],
274 /// [`Tuple`], or [`StringList`].
275 pub fn convert<T: Parseable>(&self, option: &str) -> OptionParserResult<Option<T>> {
276 match self.options.get(option).and_then(|v| v.value.as_ref()) {
277 None => Ok(None),
278 Some(v) => {
279 Ok(if v.is_empty() {
280 None
281 } else {
282 Some(Parseable::from_str(v).map_err(|_| {
283 OptionParserError::Conversion(option.to_owned(), v.to_owned())
284 })?)
285 })
286 }
287 }
288 }
289}
290
291/// A boolean-like value that accepts `"on"`, `"true"`, `"off"`, `"false"`, or `""`.

Callers 5

parseMethod · 0.80
start_vmmFunction · 0.80
parseMethod · 0.80
parseMethod · 0.80
parseMethod · 0.80

Calls 2

getMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected