pub struct Args {
pub positional: Vec<String>,
/* private fields */
}
Fields§
§positional: Vec<String>
Implementations§
Source§impl Args
impl Args
Sourcepub fn flag(&self, flag: &str) -> bool
pub fn flag(&self, flag: &str) -> bool
Examples found in repository?
examples/basic.rs (line 20)
3fn main() {
4 let mut parser = Parser::new("An example argument parser");
5 parser.add_parameter(Parameter::param("--arg0", "Argument 0, type: u32.").default(&5));
6 parser.add_parameter(Parameter::param("--arg1", "Argument 1, type: f32.").alias("-a"));
7 parser.add_parameter(Parameter::flag("--arg2", "Argument 2, flag").alias("-a2"));
8
9 let args = parser.parse_args();
10 for positional in &args.positional {
11 println!("Found positional argument: {}", positional);
12 }
13
14 let arg0 = args.get::<u32>("--arg0");
15 println!("Arg 0 was {}", arg0);
16
17 let arg1 = args.get::<f32>("--arg1");
18 println!("Arg 1 was {}", arg1);
19
20 if args.flag("--arg2") {
21 println!("Found Arg 2 flag!");
22 }
23}
Sourcepub fn get<T>(&self, param: &str) -> T
pub fn get<T>(&self, param: &str) -> T
Examples found in repository?
examples/basic.rs (line 14)
3fn main() {
4 let mut parser = Parser::new("An example argument parser");
5 parser.add_parameter(Parameter::param("--arg0", "Argument 0, type: u32.").default(&5));
6 parser.add_parameter(Parameter::param("--arg1", "Argument 1, type: f32.").alias("-a"));
7 parser.add_parameter(Parameter::flag("--arg2", "Argument 2, flag").alias("-a2"));
8
9 let args = parser.parse_args();
10 for positional in &args.positional {
11 println!("Found positional argument: {}", positional);
12 }
13
14 let arg0 = args.get::<u32>("--arg0");
15 println!("Arg 0 was {}", arg0);
16
17 let arg1 = args.get::<f32>("--arg1");
18 println!("Arg 1 was {}", arg1);
19
20 if args.flag("--arg2") {
21 println!("Found Arg 2 flag!");
22 }
23}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Args
impl RefUnwindSafe for Args
impl Send for Args
impl Sync for Args
impl Unpin for Args
impl UnwindSafe for Args
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