pub trait Input {
Show 21 methods
// Required methods
fn current(&self) -> Option<(&str, TokenKind)>;
fn current_str_with_leading_dashes(&self) -> Option<&str>;
fn bump(&mut self, len: usize) -> &str;
fn bump_with_leading_dashes(&mut self, len: usize) -> &str;
fn bump_argument(&mut self) -> Option<&str>;
fn set_ignore_dashes(&mut self, ignore: bool);
fn ignore_dashes(&self) -> bool;
// Provided methods
fn is_empty(&self) -> bool { ... }
fn is_not_empty(&self) -> bool { ... }
fn can_parse_value_no_whitespace(&self) -> bool { ... }
fn can_parse_dash_argument(&self) -> bool { ... }
fn eat_no_dash<'a>(&mut self, token: &'a str) -> Option<&str> { ... }
fn eat_one_dash<'a>(&mut self, token: &'a str) -> Option<&str> { ... }
fn eat_two_dashes<'a>(&mut self, token: &'a str) -> Option<&str> { ... }
fn eat_value<'a>(&mut self, token: &'a str) -> Option<&str> { ... }
fn eat_value_allows_leading_dashes<'a>(
&mut self,
token: &'a str,
) -> Option<&str> { ... }
fn no_dash(&mut self) -> Option<InputPart<'_, Self>>
where Self: Sized { ... }
fn one_dash(&mut self) -> Option<InputPart<'_, Self>>
where Self: Sized { ... }
fn two_dashes(&mut self) -> Option<InputPart<'_, Self>>
where Self: Sized { ... }
fn value(&mut self) -> Option<InputPart<'_, Self>>
where Self: Sized { ... }
fn value_allows_leading_dashes(&mut self) -> Option<InputPartLD<'_, Self>>
where Self: Sized { ... }
}
Expand description
The trait for types that can produce tokens from a list of command-line arguments.
To implement this trait efficiently, accessing the current token and its
TokenKind
should be cheap.
This trait is implemented for crate::StringInput.
Required Methods§
Sourcefn current(&self) -> Option<(&str, TokenKind)>
fn current(&self) -> Option<(&str, TokenKind)>
Returns the current token as string slice and the TokenKind
of the
current token, or None if the input is empty.
This function skips the leading dashes of arguments. If you don’t want
that, use Input::current_str_with_leading_dashes()
instead.
Sourcefn current_str_with_leading_dashes(&self) -> Option<&str>
fn current_str_with_leading_dashes(&self) -> Option<&str>
Returns the current token (including the leading dashes) as string slice, or None if the input is empty.
Sourcefn bump(&mut self, len: usize) -> &str
fn bump(&mut self, len: usize) -> &str
Bumps the current token by len
bytes.
Leading dashes are ignored, e.g. bumping the argument --foo
by one
byte returns f
; the rest of the token is oo
. If you don’t want
this, use Input::bump_with_leading_dashes()
instead.
If the bytes are followed by an equals sign and the current
TokenKind
is OneDash
, TwoDashes
or AfterOneDash
, the
equals sign is skipped.
If afterwards the current argument is empty, a new argument is read and becomes the “current token”
Sourcefn bump_with_leading_dashes(&mut self, len: usize) -> &str
fn bump_with_leading_dashes(&mut self, len: usize) -> &str
Bumps the current token (including leading dashes) by len
bytes.
If the bytes are followed by an equals sign and the current
TokenKind
is OneDash
, TwoDashes
or AfterOneDash
, the
equals sign is skipped.
If afterwards the current argument is empty, a new argument is read and becomes the “current token”
Sourcefn bump_argument(&mut self) -> Option<&str>
fn bump_argument(&mut self) -> Option<&str>
Bumps the current argument (including leading dashes) completely.
Sourcefn set_ignore_dashes(&mut self, ignore: bool)
fn set_ignore_dashes(&mut self, ignore: bool)
Sets the parsing mode. When true
, all arguments are considered
positional, i.e. leading dashes are ignored.
Sourcefn ignore_dashes(&self) -> bool
fn ignore_dashes(&self) -> bool
Returns the parsing mode. When true
, all arguments are considered
positional, i.e. leading dashes are ignored.
Provided Methods§
Sourcefn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Returns true
if the input is empty. This means that all arguments have
been fully parsed.
Sourcefn is_not_empty(&self) -> bool
fn is_not_empty(&self) -> bool
Returns true
if the input is not empty. This means that all arguments
have been fully parsed.
Sourcefn can_parse_value_no_whitespace(&self) -> bool
fn can_parse_value_no_whitespace(&self) -> bool
Returns true
if a value within the same argument is expected. Or in
other words, if we just consumed a single-dash flag or an equals sign
and there are remaining bytes in the same argument.
Sourcefn can_parse_dash_argument(&self) -> bool
fn can_parse_dash_argument(&self) -> bool
Returns true
if the current token can be parsed as a flag or named
argument (e.g. -h
, --help=config
).
Sourcefn eat_no_dash<'a>(&mut self, token: &'a str) -> Option<&str>
fn eat_no_dash<'a>(&mut self, token: &'a str) -> Option<&str>
Eat the current token if the argument doesn’t start with dashes and
matches token
exactly.
Sourcefn eat_one_dash<'a>(&mut self, token: &'a str) -> Option<&str>
fn eat_one_dash<'a>(&mut self, token: &'a str) -> Option<&str>
Eat the current token if the argument starts with a single dash, and the
current token starts with token
.
Does not work if the token appears after an equals sign has already been parsed.
Sourcefn eat_two_dashes<'a>(&mut self, token: &'a str) -> Option<&str>
fn eat_two_dashes<'a>(&mut self, token: &'a str) -> Option<&str>
Eat the current token if the argument starts with (at least) two dashes,
and the current token either matches token
exactly, or starts with
token
followed by an equals sign.
Does not work if the token appears after an equals sign has already been parsed.
Sourcefn eat_value<'a>(&mut self, token: &'a str) -> Option<&str>
fn eat_value<'a>(&mut self, token: &'a str) -> Option<&str>
Eat the current token if it matches token
exactly.
This method only works if the current TokenKind
is either NoDash
,
AfterOneDash
or AfterEquals
.
Sourcefn eat_value_allows_leading_dashes<'a>(
&mut self,
token: &'a str,
) -> Option<&str>
fn eat_value_allows_leading_dashes<'a>( &mut self, token: &'a str, ) -> Option<&str>
Eat the current token (including any leading dashes) if it matches
token
exactly.
Sourcefn no_dash(&mut self) -> Option<InputPart<'_, Self>>where
Self: Sized,
fn no_dash(&mut self) -> Option<InputPart<'_, Self>>where
Self: Sized,
If the argument doesn’t start with dashes, returns a helper struct for obtaining, validating and eating the next token.
Sourcefn one_dash(&mut self) -> Option<InputPart<'_, Self>>where
Self: Sized,
fn one_dash(&mut self) -> Option<InputPart<'_, Self>>where
Self: Sized,
If the argument starts with a single dash, returns a helper struct for obtaining, validating and eating the next token.
Sourcefn two_dashes(&mut self) -> Option<InputPart<'_, Self>>where
Self: Sized,
fn two_dashes(&mut self) -> Option<InputPart<'_, Self>>where
Self: Sized,
If the argument starts with two (or more) dashes, returns a helper struct for obtaining, validating and eating the next token.
Sourcefn value(&mut self) -> Option<InputPart<'_, Self>>where
Self: Sized,
fn value(&mut self) -> Option<InputPart<'_, Self>>where
Self: Sized,
Returns a helper struct for obtaining, validating and eating the next
token. Works only if the current TokenKind
is either NoDash
,
AfterOneDash
or AfterEquals
.
The value is not allowed to start with a dash, unless the dash is not at the start of the current argument.
Sourcefn value_allows_leading_dashes(&mut self) -> Option<InputPartLD<'_, Self>>where
Self: Sized,
fn value_allows_leading_dashes(&mut self) -> Option<InputPartLD<'_, Self>>where
Self: Sized,
Returns a helper struct for obtaining, validating and eating the next token. The value is allowed to start with a dash.