Add note on reasoning in optional argument parsing behavior

This commit is contained in:
Imbris 2022-03-13 16:00:18 -04:00
parent 008e9051f7
commit 06b605a8d0

View File

@ -445,6 +445,18 @@ macro_rules! parse_args {
{
let mut args = $args.into_iter().peekable();
(
// We only consume the input argument when parsing is successful. If this fails, we
// will then attempt to parse it as the next argument type. This is done regardless
// of whether the argument is optional because that information is not available
// here. Nevertheless, if the caller only precedes to use the parsed arguments when
// all required arguments parse successfully to `Some(val)` this should not create
// any unexpected behavior.
//
// This does mean that optional arguments will be included in the trailing args or
// that one optional arg could be interpreted as another, if the user makes a
// mistake that causes an optional arg to fail to parse. But there is no way to
// discern this in the current model with the optional args and trailing arg being
// solely position based.
$({
let parsed = args.peek().and_then(|s| s.parse::<$t>().ok());
// Consume successfully parsed arg.