Skip to main content

ValueEnum

Trait ValueEnum 

Source
pub trait ValueEnum: Sized {
    const CHOICES: &'static [&'static str];
    const ACCEPTED_CHOICES: &'static [&'static str] = Self::CHOICES;
    const ALIASES: &'static [(&'static str, &'static str)] = _;
    const DETAILS: &'static [ChoiceMeta<'static>] = _;
    const IGNORE_CASE: bool = false;

    // Required method
    fn from_choice(value: &str) -> Option<Self>;
}
Expand description

A struct that describes one command’s flags and arguments.

Implemented by the derive on a subcommand’s argument struct. The root’s generated parse needs to name the type that accumulates a subcommand’s values while parsing, and cannot know which module the derive put it in — an associated type is how it names it regardless. A type whose values are a fixed set of words.

What a CLI calls an enum: --shell bash. The words are what the spec lists as choices, so declaring them once on the type keeps help, completions and the check that rejects a wrong value reading from the same place — rather than a list in an attribute that has to be kept in step with the type by hand.

Required Associated Constants§

Source

const CHOICES: &'static [&'static str]

Every word this type accepts, in the order it declared them.

Provided Associated Constants§

Source

const ACCEPTED_CHOICES: &'static [&'static str] = Self::CHOICES

Canonical words plus aliases accepted by the type.

Source

const ALIASES: &'static [(&'static str, &'static str)] = _

Canonical-to-alias pairs, used by spec emission to retain the distinction.

Source

const DETAILS: &'static [ChoiceMeta<'static>] = _

Presentation metadata for canonical values and aliases.

Source

const IGNORE_CASE: bool = false

Required Methods§

Source

fn from_choice(value: &str) -> Option<Self>

Convert one canonical word or alias into its enum variant.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§