pub struct ArgParseResults { /* private fields */ }
Expand description
This type represents the result ofparsing arguments.
Implementations§
Source§impl ArgParseResults
impl ArgParseResults
Sourcepub fn get<T: FromStr>(&self, name: &str) -> Option<T>
pub fn get<T: FromStr>(&self, name: &str) -> Option<T>
Extracts the argument, as long is the value type implements
FromStr
§Example
use argparse::{ArgParser, ArgType};
let mut parser = ArgParser::new("runner".into());
parser.add_opt("verbose", Some("false"), 'v', false,
"Whether to produce verbose output", ArgType::Flag);
// Normally you'd get this from std::env::args().iter()
let test_1 = "./runner -v".split_whitespace()
.map(|s| s.into())
.collect::<Vec<String>>();
if let Ok(p_res) = parser.parse(test_1.iter()) {
if let Some(true) = p_res.get::<bool>("verbose") {
// be verbose
}
}
Sourcepub fn get_with<T, P>(&self, name: &str, parser: P) -> Option<T>where
P: ArgGetter<T>,
pub fn get_with<T, P>(&self, name: &str, parser: P) -> Option<T>where
P: ArgGetter<T>,
Extracts the argument, using the ArgGetter<T>
that you provided
§Note
See documentation for the trait ArgGetter
for more information
§Example
use argparse::{ArgParser, ArgType};
let mut parser = ArgParser::new("runner".into());
parser.add_opt("verbose", Some("false"), 'v', false,
"Whether to produce verbose output", ArgType::Flag);
// Normally you'd get this from std::env::args().iter()
let test_1 = "./runner -v".split_whitespace()
.map(|s| s.into())
.collect::<Vec<String>>();
let dumb_closure = |_: &str| { Some(true) };
if let Ok(p_res) = parser.parse(test_1.iter()) {
if let Some(true) = p_res.get_with::<bool, _>("verbose", dumb_closure) {
// be verbose
}
}
Trait Implementations§
Source§impl Clone for ArgParseResults
impl Clone for ArgParseResults
Source§fn clone(&self) -> ArgParseResults
fn clone(&self) -> ArgParseResults
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for ArgParseResults
impl RefUnwindSafe for ArgParseResults
impl Send for ArgParseResults
impl Sync for ArgParseResults
impl Unpin for ArgParseResults
impl UnwindSafe for ArgParseResults
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more