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
impl Index
pub fn parse_ctx(storer: &mut SpanStorer, str: &str) -> Result<(), Error>
pub fn parse(pat: &str) -> Result<Self, Error>
pub fn is_null(&self) -> bool
pub fn is_forward(&self) -> bool
pub fn is_backward(&self) -> bool
pub fn is_list(&self) -> bool
pub fn is_except(&self) -> bool
pub fn is_range(&self) -> bool
pub fn is_anywhere(&self) -> bool
pub fn to_help(&self) -> String
pub fn forward(index: usize) -> Self
pub fn backward(index: usize) -> Self
pub fn list(list: Vec<usize>) -> Self
pub fn except(list: Vec<usize>) -> Self
pub fn range(start: Option<usize>, end: Option<usize>) -> Self
pub fn anywhere() -> Self
pub fn null() -> Self
pub fn calc_index(&self, noa_index: usize, noa_count: usize) -> Option<usize>
Trait Implementations§
source§impl Ord for Index
impl Ord for Index
source§impl PartialEq for Index
impl PartialEq for Index
source§impl PartialOrd for Index
impl PartialOrd for Index
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more