pub trait ValueEnum: Sized + Clone {
fn value_variants<'a>() -> &'a [Self]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
;
fn to_possible_value<'a>(&self) -> Option<PossibleValue<'a>>;
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
#[clap(value_enum)]
which will
- Call
Arg::possible_values
- Allowing using the
#[clap(default_value_t)]
attribute without implementingDisplay
.
See the derive reference for attributes and best practices.
NOTE: Deriving requires the [derive
feature flag][crate::_features]
Example
ⓘ
#[derive(clap::Parser)]
struct Args {
#[clap(value_enum)]
level: Level,
}
#[derive(clap::ValueEnum, Clone)]
enum Level {
Debug,
Info,
Warning,
Error,
}
Required Methods
sourcefn value_variants<'a>() -> &'a [Self]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
fn value_variants<'a>() -> &'a [Self]ⓘNotable traits for &[u8]impl Read for &[u8]impl Write for &mut [u8]
All possible argument values, in display order.
sourcefn to_possible_value<'a>(&self) -> Option<PossibleValue<'a>>
fn to_possible_value<'a>(&self) -> Option<PossibleValue<'a>>
The canonical argument value.
The value is None
for skipped variants.