Programming-Idioms

History of Idiom 162 > diff from v8 to v9

Edit summary for version 9 :
New Rust implementation by user [GobbleCock]

Version 8

2017-10-28, 13:18:02

Version 9

2018-06-12, 09:46:03

Idiom #162 Execute procedures depending on options

execute bat if b is a program option and fox if f is a program option.

Idiom #162 Execute procedures depending on options

execute bat if b is a program option and fox if f is a program option.

Code
if let Some(arg) = ::std::env::args().nth(1) {
    if &arg == "f" {
        fox();
    } else if &arg = "b" {
        bat();
    } else {
	eprintln!("invalid argument: {}", arg),
    }
} else {
    eprintln!("missing argument");
}
Doc URL
https://doc.rust-lang.org/nightly/std/env/fn.args.html