Skip to main content

TokenRole

Enum TokenRole 

Source
#[non_exhaustive]
pub enum TokenRole {
Show 13 variants Program, Command { name: String, }, Flag { flag: Arc<SpecFlag>, spelling: String, negated: bool, }, Value { flag: Arc<SpecFlag>, values: Vec<String>, attached: bool, }, Arg { arg: Arc<SpecArg>, values: Vec<String>, }, Separator, Builtin { spelling: String, }, ValueTerminator { ends: String, }, Restart, UnknownFlag { bound_as: Option<Arc<SpecArg>>, }, Refused { reason: String, }, External, Unread,
}
Expand description

What one word of the command line became.

Several because a single token can do more than one thing: -abc sets three flags, -j8 is a flag and its value.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Program

argv[0]. Also a Command when a multicall symlink makes the basename a word.

§

Command

Selected a subcommand.

Fields

§name: String
§

Flag

Named a flag, in this spelling. negated for the negate form.

Fields

§spelling: String
§negated: bool
§

Value

Supplied a flag’s value. Several values when a delimiter split the word.

Fields

§values: Vec<String>
§attached: bool

Whether the value rode along on the flag’s own token (--env=prod, -j8) rather than following it as its own word.

§

Arg

Filled a positional argument. Several values when a delimiter split the word.

Fields

§values: Vec<String>
§

Separator

An explicit --, consumed as a separator.

§

Builtin

A word the parser answers itself rather than binding: --help, -h, --version, -V. The parse stops here and the answer travels as an error carrying the text, so without a role the word reads as having done nothing while a whole help page arrives in the error list.

Fields

§spelling: String
§

ValueTerminator

A declared value_terminator, consumed to end a run of values. ends names the declaration whose run it closed — the word is not one of that run’s values, which is the whole reason it was declared.

Fields

§ends: String
§

Restart

A declared restart_token: the positional cursor and the values it had filled start over here. Recorded because the words before it are still in the report, and without this row they look like they filled arguments that then came back empty.

§

UnknownFlag

A flag-like word no declaration matched. bound_as is the positional that took it under unknown_flags="value", and None when the word was refused.

Fields

§bound_as: Option<Arc<SpecArg>>
§

Refused

The word reached a declaration that would not take it, and was dropped. Without this the token reads as having done nothing, which is the one thing it did not do.

Fields

§reason: String
§

External

Forwarded to an external subcommand.

§

Unread

The parser stopped before this word — a help request, a refused value.

Trait Implementations§

Source§

impl Clone for TokenRole

Source§

fn clone(&self) -> TokenRole

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TokenRole

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.