Values

Struct Values 

Source
pub struct Values { /* private fields */ }
Expand description

Values is a structure which contains all of the parsed command-line flag values (or the default values for those flags). If parsing fails (including if some required flags weren’t specified, for example), an error is returned.

This structure provides various accessor functions, to conveniently get at the flag values. These accessors tend to follow the pattern of assuming the caller is doing things correctly, and that the caller wants us to panic early if something goes wrong. If this is not the desired behavior, the Values::get accessor provides a safe API where the caller can do their own error handling.

Implementations§

Source§

impl Values

Source

pub fn new( default_values: HashMap<String, Value>, values: HashMap<String, Value>, ) -> Values

Construct a new Values structure using the given default values, and the given values parsed from the program’s command-line flags.

Source

pub fn contains_key(&self, name: &str) -> bool

Returns whether or not there exists a Value for the given flag.

Source

pub fn get(&self, name: &str) -> Vec<&str>

Return the Value(s) of a single flag, as strings. The returned vector might be empty (if there is no Value associated with the flag), or it might contain exactly one entry (in the case of named or boolean flags), or it might contain many entries (in the case of positional flags).

Source

pub fn get_as<E, T>(&self, name: &str) -> Result<Vec<T>, E>
where T: FromStr<Err = E>,

Return the Value(s) of a single flag, parsed into the given type. This is a convenience wrapper around get.

Trait Implementations§

Source§

impl Debug for Values

Source§

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

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

impl From<HashMap<String, Value>> for Values

Source§

fn from(values: HashMap<String, Value>) -> Values

Converts to this type from the input type.
Source§

impl FromIterator<(String, Value)> for Values

Source§

fn from_iter<T>(iter: T) -> Values
where T: IntoIterator<Item = (String, Value)>,

Creates a value from an iterator. Read more
Source§

impl PartialEq for Values

Source§

fn eq(&self, other: &Values) -> 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 Eq for Values

Source§

impl StructuralPartialEq for Values

Auto Trait Implementations§

§

impl Freeze for Values

§

impl RefUnwindSafe for Values

§

impl Send for Values

§

impl Sync for Values

§

impl Unpin for Values

§

impl UnwindSafe for Values

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.