pub struct Matches {
pub(crate) opts: Vec<Opt>,
pub(crate) vals: Vec<Vec<(usize, Optval)>>,
pub free: Vec<String>,
}
Expand description
The result of checking command line arguments. Contains a vector of matches and a vector of free strings.
Fields§
§opts: Vec<Opt>
Options that matched
vals: Vec<Vec<(usize, Optval)>>
Values of the Options that matched and their positions
free: Vec<String>
Free string fragments
Implementations§
source§impl Matches
impl Matches
pub(crate) fn opt_vals(&self, nm: &str) -> Vec<(usize, Optval)>
pub(crate) fn opt_val(&self, nm: &str) -> Option<Optval>
sourcepub fn opt_defined(&self, nm: &str) -> bool
pub fn opt_defined(&self, nm: &str) -> bool
Returns true if an option was defined
sourcepub fn opt_present(&self, nm: &str) -> bool
pub fn opt_present(&self, nm: &str) -> bool
Returns true if an option was matched.
sourcepub fn opt_positions(&self, nm: &str) -> Vec<usize>
pub fn opt_positions(&self, nm: &str) -> Vec<usize>
Returns a vector of all the positions in which an option was matched.
sourcepub fn opts_present(&self, names: &[String]) -> bool
pub fn opts_present(&self, names: &[String]) -> bool
Returns true if any of several options were matched.
sourcepub fn opts_str(&self, names: &[String]) -> Option<String>
pub fn opts_str(&self, names: &[String]) -> Option<String>
Returns the string argument supplied to one of several matching options or None
.
sourcepub fn opt_strs(&self, nm: &str) -> Vec<String>
pub fn opt_strs(&self, nm: &str) -> Vec<String>
Returns a vector of the arguments provided to all matches of the given option.
Used when an option accepts multiple values.
sourcepub fn opt_strs_pos(&self, nm: &str) -> Vec<(usize, String)>
pub fn opt_strs_pos(&self, nm: &str) -> Vec<(usize, String)>
Returns a vector of the arguments provided to all matches of the given option, together with their positions.
Used when an option accepts multiple values.
sourcepub fn opt_str(&self, nm: &str) -> Option<String>
pub fn opt_str(&self, nm: &str) -> Option<String>
Returns the string argument supplied to a matching option or None
.
sourcepub fn opt_default(&self, nm: &str, def: &str) -> Option<String>
pub fn opt_default(&self, nm: &str, def: &str) -> Option<String>
Returns the matching string, a default, or None
.
Returns None
if the option was not present, def
if the option was
present but no argument was provided, and the argument if the option was
present and an argument was provided.
sourcepub fn opt_get<T>(&self, nm: &str) -> Result<Option<T>, T::Err>where
T: FromStr,
pub fn opt_get<T>(&self, nm: &str) -> Result<Option<T>, T::Err>where
T: FromStr,
Returns some matching value or None
.
Similar to opt_str, also converts matching argument using FromStr.
sourcepub fn opt_get_default<T>(&self, nm: &str, def: T) -> Result<T, T::Err>where
T: FromStr,
pub fn opt_get_default<T>(&self, nm: &str, def: T) -> Result<T, T::Err>where
T: FromStr,
Returns a matching value or default.
Similar to opt_default, except the two differences.
Instead of returning None when argument was not present, return def
.
Instead of returning &str return type T, parsed using str::parse().