Struct clap::builder::PossibleValue

source ·
pub struct PossibleValue<'help> { /* private fields */ }
Expand description

A possible value of an argument.

This is used for specifying possible values of Args.

NOTE: This struct is likely not needed for most usecases as it is only required to hide single values from help messages and shell completions or to attach help to possible values.

§Examples

let cfg = Arg::new("config")
    .takes_value(true)
    .value_name("FILE")
    .value_parser([
        PossibleValue::new("fast"),
        PossibleValue::new("slow").help("slower than fast"),
        PossibleValue::new("secret speed").hide(true)
    ]);

Implementations§

source§

impl<'help> PossibleValue<'help>

source

pub fn new(name: &'help str) -> Self

Create a PossibleValue with its name.

The name will be used to decide whether this value was provided by the user to an argument.

NOTE: In case it is not hidden it will also be shown in help messages for arguments that use it as a possible value and have not hidden them through Arg::hide_possible_values(true).

§Examples
PossibleValue::new("fast")
source

pub fn help(self, help: &'help str) -> Self

Sets the help description of the value.

This is typically displayed in completions (where supported) and should be a short, one-line description.

§Examples
PossibleValue::new("slow")
    .help("not fast")
source

pub fn hide(self, yes: bool) -> Self

Hides this value from help and shell completions.

This is an alternative to hiding through Arg::hide_possible_values(true), if you only want to hide some values.

§Examples
PossibleValue::new("secret")
    .hide(true)
source

pub fn alias(self, name: &'help str) -> Self

Sets a hidden alias for this argument value.

§Examples
PossibleValue::new("slow")
    .alias("not-fast")
source

pub fn aliases<I>(self, names: I) -> Self
where I: IntoIterator<Item = &'help str>,

Sets multiple hidden aliases for this argument value.

§Examples
PossibleValue::new("slow")
    .aliases(["not-fast", "snake-like"])
source§

impl<'help> PossibleValue<'help>

Reflection

source

pub fn get_name(&self) -> &'help str

Get the name of the argument value

source

pub fn get_help(&self) -> Option<&'help str>

Get the help specified for this argument, if any

source

pub fn is_hidden(&self) -> bool

Deprecated, replaced with PossibleValue::is_hide_set

source

pub fn is_hide_set(&self) -> bool

Report if PossibleValue::hide is set

source

pub fn get_visible_name(&self) -> Option<&'help str>

Get the name if argument value is not hidden, None otherwise

source

pub fn get_name_and_aliases(&self) -> impl Iterator<Item = &'help str> + '_

Returns all valid values of the argument value.

Namely the name and all aliases.

source

pub fn matches(&self, value: &str, ignore_case: bool) -> bool

Tests if the value is valid for this argument value

The value is valid if it is either the name or one of the aliases.

§Examples
let arg_value = PossibleValue::new("fast").alias("not-slow");

assert!(arg_value.matches("fast", false));
assert!(arg_value.matches("not-slow", false));

assert!(arg_value.matches("FAST", true));
assert!(!arg_value.matches("FAST", false));

Trait Implementations§

source§

impl<'help> Clone for PossibleValue<'help>

source§

fn clone(&self) -> PossibleValue<'help>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'help> Debug for PossibleValue<'help>

source§

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

Formats the value using the given formatter. Read more
source§

impl<'help> Default for PossibleValue<'help>

source§

fn default() -> PossibleValue<'help>

Returns the “default value” for a type. Read more
source§

impl<'help> From<&'help &'help str> for PossibleValue<'help>

source§

fn from(s: &'help &'help str) -> Self

Converts to this type from the input type.
source§

impl<'help> From<&'help str> for PossibleValue<'help>

source§

fn from(s: &'help str) -> Self

Converts to this type from the input type.
source§

impl<'help> PartialEq for PossibleValue<'help>

source§

fn eq(&self, other: &PossibleValue<'help>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'help> Eq for PossibleValue<'help>

source§

impl<'help> StructuralPartialEq for PossibleValue<'help>

Auto Trait Implementations§

§

impl<'help> Freeze for PossibleValue<'help>

§

impl<'help> RefUnwindSafe for PossibleValue<'help>

§

impl<'help> Send for PossibleValue<'help>

§

impl<'help> Sync for PossibleValue<'help>

§

impl<'help> Unpin for PossibleValue<'help>

§

impl<'help> UnwindSafe for PossibleValue<'help>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

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

Performs the conversion.