pub_just

Trait ValueEnum

Source
pub trait ValueEnum: Sized + Clone {
    // Required methods
    fn value_variants<'a>() -> &'a [Self];
    fn to_possible_value(&self) -> Option<PossibleValue>;

    // Provided method
    fn from_str(input: &str, ignore_case: bool) -> Result<Self, String> { ... }
}
Expand description

Parse arguments into enums.

When deriving Parser, a field whose type implements ValueEnum can have the attribute #[arg(value_enum)] which will

  • Call EnumValueParser
  • Allowing using the #[arg(default_value_t)] attribute without implementing Display.

NOTE: Deriving requires the derive feature flag

Required Methodsยง

Source

fn value_variants<'a>() -> &'a [Self]

All possible argument values, in display order.

Source

fn to_possible_value(&self) -> Option<PossibleValue>

The canonical argument value.

The value is None for skipped variants.

Provided Methodsยง

Source

fn from_str(input: &str, ignore_case: bool) -> Result<Self, String>

Parse an argument into Self.

Dyn Compatibilityยง

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Typesยง

Sourceยง

impl ValueEnum for Shell

Implementorsยง