pub enum ParsingStyle {
    AllOptions,
    StopAtFirstFree,
}
Expand description

Controls behavior of free arguments in Parser

The parse_args_default and parse_args_default_or_exit functions will use the default parsing style, AllOptions.

Examples

use gumdrop::{Options, ParsingStyle};

#[derive(Options)]
struct MyOptions {
    // If the "-o" is parsed as an option, this will be `true`.
    option: bool,
    // All free (non-option) arguments will be collected into this Vec.
    #[options(free)]
    free: Vec<String>,
}

// Command line arguments.
let args = &["foo", "-o", "bar"];

// Using the `AllOptions` parsing style, the "-o" argument in the middle of args
// will be parsed as an option.
let opts = MyOptions::parse_args(args, ParsingStyle::AllOptions).unwrap();

assert_eq!(opts.option, true);
assert_eq!(opts.free, vec!["foo", "bar"]);

// Using the `StopAtFirstFree` option, the first non-option argument will terminate
// option parsing. That means "-o" is treated as a free argument.
let opts = MyOptions::parse_args(args, ParsingStyle::StopAtFirstFree).unwrap();

assert_eq!(opts.option, false);
assert_eq!(opts.free, vec!["foo", "-o", "bar"]);

Variants

AllOptions

Process all option arguments that appear

StopAtFirstFree

After the first “free” argument is encountered, all remaining arguments will be considered “free” arguments.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the default parsing style, AllOptions.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

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.