-
Im having some trouble with positionals. According to my understanding Yet the second case fails to parse. Am I just being stupid here?
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
By default This should work the way you describe. #[derive(Debug, PartialEq, Eq)]
struct Out {
first: Option<String>,
last: String,
}
fn the_parser() -> OptionParser<Out> {
let first = positional::<String>("first")
.parse(|v| {
if v.contains(':') {
Ok(v)
} else {
Err("no colon")
}
})
.optional()
.catch();
let last = positional::<String>("last");
construct!(Out { first, last }).to_options()
} |
Beta Was this translation helpful? Give feedback.
-
Whoops, completely missed the existence of |
Beta Was this translation helpful? Give feedback.
By default
optional
would propagate parse error outwards, you can slapcatch
at the end to returnNone
instead.This should work the way you describe.