Skip to main content

ValueEnum

Trait ValueEnum 

Source
pub trait ValueEnum: Sized + 'static {
    const VARIANTS: &'static [Self];
    const POSSIBLE_VALUES: &'static [&'static str];

    // Required methods
    fn value_name(&self) -> &'static str;
    fn from_value(value: &str) -> Option<Self>;
}
Expand description

An enum whose variants are the accepted values of an argument.

Usually implemented with #[derive(ValueEnum)]. Fields of a ValueEnum type marked with #[arg(value_enum)] are parsed with from_value and list their POSSIBLE_VALUES in the generated help.

Required Associated Constants§

Source

const VARIANTS: &'static [Self]

Every variant, in declaration order.

Source

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

The name of every variant, in declaration order, as accepted on the command line and shown in the generated help. Aliases are not included.

Required Methods§

Source

fn value_name(&self) -> &'static str

Returns the name of this variant, as listed in POSSIBLE_VALUES.

Source

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

Returns the variant whose name or alias is exactly value, if any.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§