palex

Struct StringInput

Source
pub struct StringInput<I: Iterator<Item = String> = Args> { /* private fields */ }
Expand description

The default input type for argument parsing. This is generic over its iterator type and can be used with std::env::args. See StringInput::new() for more information.

Getting the current token and token kind is very cheap. Bumping the token is a bit more expensive, since it involves more complicated logic and might re-allocate.

Implementations§

Source§

impl<I: Iterator<Item = String>> StringInput<I>

Source

pub fn new(iter: I) -> Self

Creates a new instance of this input.

§Example:
let mut _input = StringInput::new(std::env::args());

You probably want to discard the first argument in this case, which is just the path to the executable.

Trait Implementations§

Source§

impl<I: Iterator<Item = String>> Input for StringInput<I>

Source§

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. Read more
Source§

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.
Source§

fn bump(&mut self, len: usize) -> &str

Bumps the current token by len bytes. Read more
Source§

fn bump_with_leading_dashes(&mut self, len: usize) -> &str

Bumps the current token (including leading dashes) by len bytes. Read more
Source§

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

Bumps the current argument (including leading dashes) completely.
Source§

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.
Source§

fn ignore_dashes(&self) -> bool

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

fn is_empty(&self) -> bool

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

fn is_not_empty(&self) -> bool

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

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.
Source§

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

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.
Source§

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. Read more
Source§

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. Read more
Source§

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

Eat the current token if it matches token exactly. Read more
Source§

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.
Source§

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.
Source§

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.
Source§

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.
Source§

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. Read more
Source§

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.

Auto Trait Implementations§

§

impl<I> Freeze for StringInput<I>
where I: Freeze,

§

impl<I> RefUnwindSafe for StringInput<I>
where I: RefUnwindSafe,

§

impl<I> Send for StringInput<I>
where I: Send,

§

impl<I> Sync for StringInput<I>
where I: Sync,

§

impl<I> Unpin for StringInput<I>
where I: Unpin,

§

impl<I> UnwindSafe for StringInput<I>
where I: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.