Struct aopt::opt::StrParser

source ·
pub struct StrParser;
Expand description

Parse the option string with given prefixs, return an ConstrctInfo.

The struct of the option string are:

[--option][=][type][!][@index]
     |     |    |   |   |
     |     |    |   |   |
     |     |    |   |   |
     |     |    |   |   The index part of option. Here are all the possible string:
     |     |    |   |   @1 means first position
     |     |    |   |   @-1 means last position
     |     |    |   |   @[1, 2, 3] means the position 1, 2 and 3
     |     |    |   |   @-[1, 2] means except the position 1, 2
     |     |    |   |   @>2 means position that bigger than 2
     |     |    |   |   @<3 means position less than 3
     |     |    |   |   @* means all the position
     |     |    |   |
     |     |    |   Indicate the option is force required.
     |     |    |
     |     |    |
     |     |    |
     |     |    The type name of option.
     |     |    
     |     The delimiter of option name and type.
     |
     The option name part, it must be provide by user.

Example

    let parser = StrParser::default();
    let ret = parser.parse("--aopt=t!".into())?;

    assert_eq!(ret.name , Some(astr("--aopt")));
    assert_eq!(ret.type_name, Some(astr("t")));
    assert_eq!(ret.force, Some(true));
    assert_eq!(ret.index, None);

    let ret = parser.parse("bopt=t@[1,2,3]".into())?;

    assert_eq!(ret.name , Some(astr("bopt")));
    assert_eq!(ret.type_name, Some(astr("t")));
    assert_eq!(ret.force, None);
    assert_eq!(ret.idx(), Some(&Index::list(vec![1, 2, 3])));

For more examples, please reference test case test_option_str_parser.

Implementations§

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more