Function opt

Source
pub fn opt<T>(
    short: &str,
    long: &str,
    doc: &str,
    hint: &str,
) -> impl Arg<Item = Option<T>>
where T: FromStr, <T as FromStr>::Err: Debug + Display,
Examples found in repository?
examples/area.rs (line 6)
5fn main() {
6    match opt::<f32>("", "width", "", "")
7        .depend(opt::<f32>("", "height", "", ""))
8        .option_map(|(x, y)| (x, y))
9        .option_map(|(x, y)| x * y)
10        .required()
11        .parse_env()
12        .result
13    {
14        Ok(area) => println!("area: {:?}", area),
15        Err(e) => panic!("{}", e),
16    }
17}
More examples
Hide additional examples
examples/dimensions.rs (line 14)
12    fn args() -> impl Arg<Item = Self> {
13        let window = args_depend! {
14            opt("", "width", "", ""),
15            opt("", "height", "", ""),
16        }
17        .option_map(|(width, height)| Dimensions::Window { width, height });
18        let fullscreen = flag("", "fullscreen", "").some_if(Dimensions::Fullscreen);
19        window.choice(fullscreen).required()
20    }