Skip to content

Fallback for Option? #310

Answered by pacak
failable asked this question in Q&A
Discussion options

You must be logged in to vote

First let's take a look at the code that gets generated in both cases:

let revision = long("revision").argument::<String>("ARG").optional().fallback(Some(String::from("main")));
let revision2 = long("revision2").argument::<String>("ARG").fallback(String::from("main"));

Both fallback and optional work by catching "item not found" error and converting it into a value - specified value in case of fallback and None in case of optional. Later additionally wraps present value with Some.

If revision is always will be present either from user input or from the fall…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pacak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
parsing Running the parser to get results
2 participants