Struct EnumValueParser

struct EnumValueParser<E: crate::ValueEnum + Clone + Send + Sync + 'static>(_)

Parse an [ValueEnum][crate::ValueEnum] value.

See also:

Example

# use clap_builder as clap;
# use std::ffi::OsStr;
# use clap::ColorChoice;
# use clap::builder::TypedValueParser;
# let cmd = clap::Command::new("test");
# let arg = None;

// Usage
let mut cmd = clap::Command::new("raw")
    .arg(
        clap::Arg::new("color")
            .value_parser(clap::builder::EnumValueParser::<ColorChoice>::new())
            .required(true)
    );

let m = cmd.try_get_matches_from_mut(["cmd", "always"]).unwrap();
let port: ColorChoice = *m.get_one("color")
    .expect("required");
assert_eq!(port, ColorChoice::Always);

// Semantics
let value_parser = clap::builder::EnumValueParser::<ColorChoice>::new();
// or
let value_parser = clap::value_parser!(ColorChoice);
assert!(value_parser.parse_ref(&cmd, arg, OsStr::new("random")).is_err());
assert!(value_parser.parse_ref(&cmd, arg, OsStr::new("")).is_err());
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("always")).unwrap(), ColorChoice::Always);
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("auto")).unwrap(), ColorChoice::Auto);
assert_eq!(value_parser.parse_ref(&cmd, arg, OsStr::new("never")).unwrap(), ColorChoice::Never);

Implementations

impl<E: crate::ValueEnum + Clone + Send + Sync + 'static> EnumValueParser<E>

fn new() -> Self

Parse an [ValueEnum][crate::ValueEnum]

impl<E> Freeze for EnumValueParser<E>

impl<E> RefUnwindSafe for EnumValueParser<E>

impl<E> Send for EnumValueParser<E>

impl<E> Sync for EnumValueParser<E>

impl<E> Unpin for EnumValueParser<E>

impl<E> UnsafeUnpin for EnumValueParser<E>

impl<E> UnwindSafe for EnumValueParser<E>

impl<E: $crate::clone::Clone + crate::ValueEnum + Clone + Send + Sync + 'static> Clone for EnumValueParser<E>

fn clone(self: &Self) -> EnumValueParser<E>

impl<E: $crate::fmt::Debug + crate::ValueEnum + Clone + Send + Sync + 'static> Debug for EnumValueParser<E>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<E: crate::ValueEnum + Clone + Send + Sync + 'static> Default for EnumValueParser<E>

fn default() -> Self

impl<E: crate::ValueEnum + Clone + Send + Sync + 'static> TypedValueParser for EnumValueParser<E>

fn parse_ref(self: &Self, cmd: &Command, arg: Option<&Arg>, value: &OsStr) -> Result<<Self as >::Value, Error>
fn possible_values(self: &Self) -> Option<Box<dyn Iterator<Item = PossibleValue> + '_>>

impl<I> IntoResettable for EnumValueParser<E>

fn into_resettable(self: Self) -> Resettable<ValueParser>

impl<T> Any for EnumValueParser<E>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for EnumValueParser<E>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for EnumValueParser<E>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for EnumValueParser<E>

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for EnumValueParser<E>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for EnumValueParser<E>

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for EnumValueParser<E>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for EnumValueParser<E>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for EnumValueParser<E>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>