Struct Optional

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

Source

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
Hide additional 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§

Source§

impl<'a, T> CliOption for Optional<'a, T>

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> 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more