pub struct ArgValue<'help> { /* private fields */ }
Expand description
The representation of 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 about to possible values.
Examples
let cfg = Arg::new("config")
.takes_value(true)
.value_name("FILE")
.possible_value(ArgValue::new("fast"))
.possible_value(ArgValue::new("slow").about("slower than fast"))
.possible_value(ArgValue::new("secret speed").hidden(true));
Implementations
sourceimpl<'help> ArgValue<'help>
impl<'help> ArgValue<'help>
Getters
Should the value be hidden from help messages and completion
sourcepub fn get_visible_name(&self) -> Option<&str>
pub fn get_visible_name(&self) -> Option<&str>
Get the name if argument value is not hidden, None
otherwise
sourcepub fn get_name_and_aliases(&self) -> impl Iterator<Item = &str>
pub fn get_name_and_aliases(&self) -> impl Iterator<Item = &str>
Returns all valid values of the argument value. Namely the name and all aliases.
sourcepub fn matches(&self, value: &str, ignore_case: bool) -> bool
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 = ArgValue::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));
sourceimpl<'help> ArgValue<'help>
impl<'help> ArgValue<'help>
sourcepub fn new(name: &'help str) -> Self
pub fn new(name: &'help str) -> Self
Creates a new instance of ArgValue
using a string name. The name will be used to
decide wether 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
ArgValue::new("fast")
sourcepub fn about(self, about: &'help str) -> Self
pub fn about(self, about: &'help str) -> Self
Sets the help text of the value that will be displayed to the user when completing the value in a compatible shell. Typically, this is a short description of the value.
Examples
ArgValue::new("slow")
.about("not fast")
Hides this value from help text and shell completions.
This is an alternative to hiding through Arg::hide_possible_values(true)
, if you only
want to hide some values.
Examples
ArgValue::new("secret")
.hidden(true)
sourcepub fn alias(self, name: &'help str) -> Self
pub fn alias(self, name: &'help str) -> Self
Sets an alias for this argument value.
The alias will be hidden from completion and help texts.
Examples
ArgValue::new("slow")
.alias("not-fast")
sourcepub fn aliases<I>(self, names: I) -> Self where
I: IntoIterator<Item = &'help str>,
pub fn aliases<I>(self, names: I) -> Self where
I: IntoIterator<Item = &'help str>,
Sets multiple aliases for this argument value.
The aliases will be hidden from completion and help texts.
Examples
ArgValue::new("slow")
.aliases(["not-fast", "snake-like"])
Trait Implementations
impl<'help> Eq for ArgValue<'help>
impl<'help> StructuralEq for ArgValue<'help>
impl<'help> StructuralPartialEq for ArgValue<'help>
Auto Trait Implementations
impl<'help> RefUnwindSafe for ArgValue<'help>
impl<'help> Send for ArgValue<'help>
impl<'help> Sync for ArgValue<'help>
impl<'help> Unpin for ArgValue<'help>
impl<'help> UnwindSafe for ArgValue<'help>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcepub fn equivalent(&self, key: &K) -> bool
pub fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more