Trait palex::Input[][src]

pub trait Input {
    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; 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
, { ... } }

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

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.

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.

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"

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"

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

Bumps the current argument (including leading dashes) completely.

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.

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

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

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

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

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

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.

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).

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

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

fn eat_one_dash<'a>(&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.

fn eat_two_dashes<'a>(&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.

fn eat_value<'a>(&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.

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

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

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

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

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

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

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

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

fn value(&mut self) -> Option<InputPart<'_, Self>> where
    Self: Sized
[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.

fn value_allows_leading_dashes(&mut self) -> Option<InputPartLD<'_, Self>> where
    Self: Sized
[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: Iterator<Item = String>> Input for StringInput<I>[src]

Loading content...