January 2019
Intermediate to advanced
520 pages
14h 32m
English
We use the structure of branches to match subcommands from our previous examples:
match matches.subcommand() { (CMD_ADD, Some(matches)) => { let token = matches.value_of("TOKEN").unwrap(); let uid = matches.value_of("UID").unwrap(); add_session(&conn, token, uid)?; } (CMD_REMOVE, Some(matches)) => { let token = matches.value_of("TOKEN").unwrap(); remove_session(&conn, token)?; } (CMD_LIST, _) => { println!("LIST"); let sessions = list_sessions(&conn)?; for (token, uid) in sessions { println!("Token: {:20} Uid: {:20}", token, uid); } } _ => { matches.usage(); }}
For the add subcommand, we extract the TOKEN and UID values from arguments and pass them to the add_session function with a reference to a Connector. For the ...
Read now
Unlock full access