Enum aopt::opt::Index

source ·
pub enum Index {
    Forward(usize),
    Backward(usize),
    List(Vec<usize>),
    Except(Vec<usize>),
    Range(usize, Option<usize>),
    AnyWhere,
    Null,
}
Expand description

Index using for option match.

The index is the position of left arguments (non-option arguments, NOA) index.

§Example

foo.exe -a=value -b value pos1 --aopt=42 pos2 --bopt value pos3
            |     |   |    |      |       |      |     |     |
            |     |   |    |      |       |      |     |     NOA @3 or @-1
            |     |   |    |      |       |      |     value of --bopt
            |     |   |    |      |       |      option --bopt
            |     |   |    |      |       NOA @2 or @-2
            |     |   |    |    option --aopt and its value 42
            |     |   |   NOA @1
            |     |   value of -b
            |    option -b
        option -a and its value

For option check, see SetChecker for more information.

Variants§

§

Forward(usize)

The forward index of NOA, fixed position.

§Example

For ["app", "--aopt", "--bopt=42", "pos1", "--copt", "pos2", "--dopt", "value", "pos3"]:

@1 will matching "pos1".

@2 will matching "pos2".

@3 will matching "pos3".

§

Backward(usize)

The backward index of NOA, floating position.

§Example

For ["app", "--aopt", "--bopt=42", "pos1", "--copt", "pos2", "--dopt", "value", "pos3"]:

@-1 will matching "pos2".

@-2 will matching "pos1".

@-3 will matching "app".

§

List(Vec<usize>)

The include list of forward index of NOA, fixed position.

§Example

For ["app", "--aopt", "--bopt=42", "pos1", "--copt", "pos2", "--dopt", "value", "pos3"]:

@[1,3] will matching "pos1" or "pos3".

@[1,2] will matching "pos1" or "pos2".

@[1,2,3] will matching "pos1", "pos2" or "pos3".

§

Except(Vec<usize>)

The exclude list of forward index of NOA, floating position.

§Example

For ["app", "--aopt", "--bopt=42", "pos1", "--copt", "pos2", "--dopt", "value", "pos3"]:

@-[1,3] will matching "pos2".

@-[3] will matching "pos1" or "pos2".

@-[2] will matching "pos1" or "pos3".

§

Range(usize, Option<usize>)

The NOA which index inside in given position range with format (m..n].

If range have upper limit, the index is fixed position otherwise it is floating position.

§Example

For ["app", "--aopt", "--bopt=42", "pos1", "--copt", "pos2", "--dopt", "value", "pos3"]:

@0.. will matching "app", "pos1", "pos2" or "pos3".

@2.. will matching "pos2", "pos3".

@1.. will matching "pos1", "pos2" or "pos3".

@..4 will matching "app", "pos1", "pos2" or "pos3".

@..2 will matching "app", "pos1".

@1..3 will matching "pos1", "pos2".

§

AnyWhere

The anywhere position of NOA, floating position.

§Example

For ["app", "--aopt", "--bopt=42", "pos1", "--copt", "pos2", "--dopt", "value", "pos3"]:

@* will matching "app", "pos1", "pos2" or "pos3".

§

Null

Implementations§

source§

impl Index

source

pub fn parse_ctx(storer: &mut SpanStorer, str: &str) -> Result<(), Error>

source

pub fn parse(pat: &str) -> Result<Self, Error>

source

pub fn is_null(&self) -> bool

source

pub fn is_forward(&self) -> bool

source

pub fn is_backward(&self) -> bool

source

pub fn is_list(&self) -> bool

source

pub fn is_except(&self) -> bool

source

pub fn is_range(&self) -> bool

source

pub fn is_anywhere(&self) -> bool

source

pub fn to_help(&self) -> String

source

pub fn forward(index: usize) -> Self

source

pub fn backward(index: usize) -> Self

source

pub fn list(list: Vec<usize>) -> Self

source

pub fn except(list: Vec<usize>) -> Self

source

pub fn range(start: Option<usize>, end: Option<usize>) -> Self

source

pub fn anywhere() -> Self

source

pub fn null() -> Self

source

pub fn calc_index(&self, noa_index: usize, noa_count: usize) -> Option<usize>

Trait Implementations§

source§

impl Clone for Index

source§

fn clone(&self) -> Index

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Index

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Index

source§

fn default() -> Index

Returns the “default value” for a type. Read more
source§

impl Display for Index

source§

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

Formats the value using the given formatter. Read more
source§

impl Hash for Index

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Index

source§

fn cmp(&self, other: &Index) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Index

source§

fn eq(&self, other: &Index) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Index

source§

fn partial_cmp(&self, other: &Index) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a> TryFrom<&'a Range<usize>> for Index

§

type Error = Error

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

fn try_from(value: &'a Range<usize>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a RangeFrom<usize>> for Index

§

type Error = Error

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

fn try_from(value: &'a RangeFrom<usize>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a RangeFull> for Index

§

type Error = Error

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

fn try_from(value: &'a RangeFull) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a RangeInclusive<usize>> for Index

§

type Error = Error

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

fn try_from(value: &'a RangeInclusive<usize>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a RangeTo<usize>> for Index

§

type Error = Error

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

fn try_from(value: &'a RangeTo<usize>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a RangeToInclusive<usize>> for Index

§

type Error = Error

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

fn try_from(value: &'a RangeToInclusive<usize>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<&'a str> for Index

§

type Error = Error

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

fn try_from(value: &'a str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<const N: usize> TryFrom<[usize; N]> for Index

§

type Error = Error

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

fn try_from(value: [usize; N]) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<AStr> for Index

§

type Error = Error

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

fn try_from(value: AStr) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Range<usize>> for Index

§

type Error = Error

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

fn try_from(value: Range<usize>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<RangeFrom<usize>> for Index

§

type Error = Error

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

fn try_from(value: RangeFrom<usize>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<RangeFull> for Index

§

type Error = Error

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

fn try_from(value: RangeFull) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<RangeInclusive<usize>> for Index

§

type Error = Error

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

fn try_from(value: RangeInclusive<usize>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<RangeTo<usize>> for Index

§

type Error = Error

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

fn try_from(value: RangeTo<usize>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<RangeToInclusive<usize>> for Index

§

type Error = Error

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

fn try_from(value: RangeToInclusive<usize>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<String> for Index

§

type Error = Error

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

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Vec<usize>> for Index

§

type Error = Error

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

fn try_from(value: Vec<usize>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<i128> for Index

§

type Error = Error

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

fn try_from(value: i128) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<i16> for Index

§

type Error = Error

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

fn try_from(value: i16) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<i32> for Index

§

type Error = Error

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

fn try_from(value: i32) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<i64> for Index

§

type Error = Error

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

fn try_from(value: i64) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<i8> for Index

§

type Error = Error

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

fn try_from(value: i8) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<isize> for Index

§

type Error = Error

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

fn try_from(value: isize) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<u128> for Index

§

type Error = Error

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

fn try_from(value: u128) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<u16> for Index

§

type Error = Error

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

fn try_from(value: u16) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<u32> for Index

§

type Error = Error

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

fn try_from(value: u32) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<u64> for Index

§

type Error = Error

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

fn try_from(value: u64) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<u8> for Index

§

type Error = Error

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

fn try_from(value: u8) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<usize> for Index

§

type Error = Error

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

fn try_from(value: usize) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Eq for Index

source§

impl StructuralPartialEq for Index

Auto Trait Implementations§

§

impl Freeze for Index

§

impl RefUnwindSafe for Index

§

impl Send for Index

§

impl Sync for Index

§

impl Unpin for Index

§

impl UnwindSafe for Index

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

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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

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