pub struct Optional<'a, T> { /* private fields */ }
Expand description
An option parameter that maps down to Option
, taking a single value (precisely 1).
Implementations§
Source§impl<'a, T> Optional<'a, T>
impl<'a, T> Optional<'a, T>
Sourcepub fn new(variable: &'a mut Option<T>) -> Optional<'a, T>
pub fn new(variable: &'a mut Option<T>) -> Optional<'a, T>
Create an optional parameter.
Examples found in repository?
examples/reducer.rs (line 72)
53fn main() {
54 let mut _verbose: bool = false;
55 let mut operand: Operand = Operand::Add;
56 let mut initial: Option<u32> = None;
57 let mut _countries: HashSet<Country> = HashSet::default();
58 let mut items: Vec<u32> = Vec::default();
59
60 let ap = CommandLineParser::new("reducer");
61 let parser = ap
62 .add(
63 Parameter::option(Switch::new(&mut _verbose, true), "verbose", Some('v'))
64 .help("Do dee doo. We're really stretching here HAAAAAAAA HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!"),
65 )
66 .add(
67 Parameter::option(Scalar::new(&mut operand), "operand", Some('o'))
68 .help("moot")
69 .choice(Operand::Add, "+")
70 .choice(Operand::Multiply, "*"),
71 )
72 .add(Parameter::option(Optional::new(&mut initial), "initial", None)
73 .meta(vec!["testing a really long meta.. abcdefghijklmnopqrstuvwxyz"])
74 )
75 .add(Parameter::option(Collection::new(&mut _countries, Nargs::AtLeastOne), "country", None))
76 .add(
77 Parameter::argument(Collection::new(&mut items, Nargs::AtLeastOne), "item")
78 .help("The items."),
79 )
80 .build();
81 parser.parse();
82 println!("Items: {items:?}");
83 execute(_verbose, operand, initial, _countries, items);
84}
More examples
examples/foo_bar.rs (line 76)
54fn main() {
55 let mut verbose: bool = false;
56 let mut foo_bar = FooBar::Foo;
57 let mut initial: Option<u32> = None;
58 let mut countries: HashSet<Country> = HashSet::default();
59 let mut items: Vec<u32> = Vec::default();
60
61 let ap = CommandLineParser::new("foo_bar");
62 let parser = ap
63 .add(
64 Parameter::option(Switch::new(&mut verbose, true), "verbose", Some('v'))
65 .help("Do dee doo."),
66 )
67 .branch(
68 Condition::new(Scalar::new(&mut foo_bar), "foo_bar")
69 .choice(FooBar::Foo, "123 abc let's make this one medium long.")
70 .choice(FooBar::Bar, "456 def let's make this one multiple sentences. We're really stretching here HAAAAAAAA HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!")
71 .help("foo'y bar'y stuff")
72 .meta(vec!["a", "b", "c"]),
73 )
74 .command(FooBar::Foo, |sub| {
75 sub.add(Parameter::option(
76 Optional::new(&mut initial),
77 "initial",
78 None,
79 ))
80 .add(
81 Parameter::argument(Collection::new(&mut items, Nargs::Any), "item")
82 .help("The items."),
83 )
84 })
85 .command(FooBar::Bar, |sub| {
86 sub.add(Parameter::option(
87 Collection::new(&mut countries, Nargs::AtLeastOne),
88 "country",
89 None,
90 ))
91 })
92 .build();
93 parser.parse();
94 println!("Items: {items:?}");
95 execute(verbose, foo_bar, initial, countries, items);
96}
Trait Implementations§
Auto Trait Implementations§
impl<'a, T> Freeze for Optional<'a, T>
impl<'a, T> !RefUnwindSafe for Optional<'a, T>
impl<'a, T> !Send for Optional<'a, T>
impl<'a, T> !Sync for Optional<'a, T>
impl<'a, T> Unpin for Optional<'a, T>
impl<'a, T> !UnwindSafe for Optional<'a, T>
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