docs(examples): Be consistent in define and read order

This threw me off because the arguments are so similar, I kept relying
on the order but they were swapped.
This commit is contained in:
Ed Page 2021-11-11 19:10:41 -06:00
parent cdc5026410
commit 6fc9c7cff4

View file

@ -26,15 +26,6 @@ fn main() {
.arg("-l [len] 'A length to use, defaults to 10 when omitted'")
.get_matches();
// Here we get a value of type u32 from our optional -l argument.
// If the value provided to len fails to parse or not present, we default to 10
//
// Using other methods such as unwrap_or_else(|e| println!("{}",e))
// are possible too.
let len: u32 = matches.value_of_t("l").unwrap_or(10);
println!("len ({}) + 2 = {}", len, len + 2);
// This code loops through all the values provided to "seq" and adds 2
// If seq fails to parse, the program exits, you don't have an option
for v in matches
@ -43,4 +34,13 @@ fn main() {
{
println!("Sequence part {} + 2: {}", v, v + 2);
}
// Here we get a value of type u32 from our optional -l argument.
// If the value provided to len fails to parse or not present, we default to 10
//
// Using other methods such as unwrap_or_else(|e| println!("{}",e))
// are possible too.
let len: u32 = matches.value_of_t("l").unwrap_or(10);
println!("len ({}) + 2 = {}", len, len + 2);
}