Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Default value on the command line

  • In this example we set the config_file variable to the parameter passed on the command line
  • or to a default value that can be any string, including the empty string.
fn main() {
    let argv: Vec<String> = std::env::args().collect();

    let config_file = if argv.len() == 2 {
        &argv[1]
    } else {
        //""
        "config.yaml"
    };

    println!("'{}'", config_file);
}