Trait parkour::Input[][src]

pub trait Input {
    pub fn current(&self) -> Option<(&str, TokenKind)>;
pub fn current_str_with_leading_dashes(&self) -> Option<&str>;
pub fn bump(&mut self, len: usize) -> &str;
pub fn bump_with_leading_dashes(&mut self, len: usize) -> &str;
pub fn bump_argument(&mut self) -> Option<&str>;
pub fn set_ignore_dashes(&mut self, ignore: bool);
pub fn ignore_dashes(&self) -> bool; pub fn is_empty(&self) -> bool { ... }
pub fn is_not_empty(&self) -> bool { ... }
pub fn can_parse_value_no_whitespace(&self) -> bool { ... }
pub fn can_parse_dash_argument(&self) -> bool { ... }
pub fn eat_no_dash(&mut self, token: &'a str) -> Option<&str> { ... }
pub fn eat_one_dash(&mut self, token: &'a str) -> Option<&str> { ... }
pub fn eat_two_dashes(&mut self, token: &'a str) -> Option<&str> { ... }
pub fn eat_value(&mut self, token: &'a str) -> Option<&str> { ... }
pub fn eat_value_allows_leading_dashes(
        &mut self,
        token: &'a str
    ) -> Option<&str> { ... }
pub fn no_dash(&mut self) -> Option<InputPart<'_, Self>> { ... }
pub fn one_dash(&mut self) -> Option<InputPart<'_, Self>> { ... }
pub fn two_dashes(&mut self) -> Option<InputPart<'_, Self>> { ... }
pub fn value(&mut self) -> Option<InputPart<'_, Self>> { ... }
pub fn value_allows_leading_dashes(
        &mut self
    ) -> Option<InputPartLD<'_, Self>> { ... } }

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

pub fn current(&self) -> Option<(&str, TokenKind)>[src]

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.

pub fn current_str_with_leading_dashes(&self) -> Option<&str>[src]

Returns the current token (including the leading dashes) as string slice, or None if the input is empty.

pub fn bump(&mut self, len: usize) -> &str[src]

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"

pub fn bump_with_leading_dashes(&mut self, len: usize) -> &str[src]

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"

pub fn bump_argument(&mut self) -> Option<&str>[src]

Bumps the current argument (including leading dashes) completely.

pub fn set_ignore_dashes(&mut self, ignore: bool)[src]

Sets the parsing mode. When true, all arguments are considered positional, i.e. leading dashes are ignored.

pub fn ignore_dashes(&self) -> bool[src]

Returns the parsing mode. When true, all arguments are considered positional, i.e. leading dashes are ignored.

Loading content...

Provided methods

pub fn is_empty(&self) -> bool[src]

Returns true if the input is empty. This means that all arguments have been fully parsed.

pub fn is_not_empty(&self) -> bool[src]

Returns true if the input is not empty. This means that all arguments have been fully parsed.

pub fn can_parse_value_no_whitespace(&self) -> bool[src]

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.

pub fn can_parse_dash_argument(&self) -> bool[src]

Returns true if the current token can be parsed as a flag or named argument (e.g. -h, --help=config).

pub fn eat_no_dash(&mut self, token: &'a str) -> Option<&str>[src]

Eat the current token if the argument doesn't start with dashes and matches token exactly.

pub fn eat_one_dash(&mut self, token: &'a str) -> Option<&str>[src]

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.

pub fn eat_two_dashes(&mut self, token: &'a str) -> Option<&str>[src]

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.

pub fn eat_value(&mut self, token: &'a str) -> Option<&str>[src]

Eat the current token if it matches token exactly.

This method only works if the current TokenKind is either NoDash, AfterOneDash or AfterEquals.

pub fn eat_value_allows_leading_dashes(
    &mut self,
    token: &'a str
) -> Option<&str>
[src]

Eat the current token (including any leading dashes) if it matches token exactly.

pub fn no_dash(&mut self) -> Option<InputPart<'_, Self>>[src]

If the argument doesn't start with dashes, returns a helper struct for obtaining, validating and eating the next token.

pub fn one_dash(&mut self) -> Option<InputPart<'_, Self>>[src]

If the argument starts with a single dash, returns a helper struct for obtaining, validating and eating the next token.

pub fn two_dashes(&mut self) -> Option<InputPart<'_, Self>>[src]

If the argument starts with two (or more) dashes, returns a helper struct for obtaining, validating and eating the next token.

pub fn value(&mut self) -> Option<InputPart<'_, Self>>[src]

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.

pub fn value_allows_leading_dashes(&mut self) -> Option<InputPartLD<'_, Self>>[src]

Returns a helper struct for obtaining, validating and eating the next token. The value is allowed to start with a dash.

Loading content...

Implementors

impl<I> Input for StringInput<I> where
    I: Iterator<Item = String>, 
[src]

Loading content...