Struct blarg::Collection
source · pub struct Collection<'a, C, T>where
C: 'a + Collectable<T>,{ /* private fields */ }
Expand description
A parameter that takes multiple values (specifiable Nargs
).
Implementations§
source§impl<'a, C, T> Collection<'a, C, T>where
C: 'a + Collectable<T>,
impl<'a, C, T> Collection<'a, C, T>where
C: 'a + Collectable<T>,
sourcepub fn new(variable: &'a mut C, nargs: Nargs) -> Collection<'a, C, T>
pub fn new(variable: &'a mut C, nargs: Nargs) -> Collection<'a, C, T>
Create a collection parameter.
Examples found in repository?
examples/demo_summer_b.rs (line 9)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
fn main() {
let mut items: Vec<u32> = Vec::default();
let clp = CommandLineParser::new("summer");
let parser = clp
.add(
Parameter::argument(Collection::new(&mut items, Nargs::AtLeastOne), "item")
.help("The items to sum."),
)
.build();
parser.parse();
let sum: u32 = items.iter().sum();
println!("Sum: {sum}");
}
More examples
examples/demo_organization.rs (line 41)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
fn parse_tokens(parse_fn: impl FnOnce(GeneralParser) -> Result<(), i32>) -> Params {
let mut params = Params::init();
let clp = CommandLineParser::new("organization");
let parser = clp
.add(Parameter::option(
Switch::new(&mut params.verbose, true),
"verbose",
Some('v'),
))
.add(Parameter::argument(
Collection::new(&mut params.items, Nargs::AtLeastOne),
"item",
))
.build();
// The parse_fn signature is a `Result`.
// However, since `GeneralParser::parse` does not return an error (it uses `std::process::exit` under the hood), the `Err` case is only reached via test.
parse_fn(parser).expect("test-reachable-only");
params
}
examples/reducer.rs (line 75)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
fn main() {
let mut _verbose: bool = false;
let mut operand: Operand = Operand::Add;
let mut initial: Option<u32> = None;
let mut _countries: HashSet<Country> = HashSet::default();
let mut items: Vec<u32> = Vec::default();
let ap = CommandLineParser::new("reducer");
let parser = ap
.add(
Parameter::option(Switch::new(&mut _verbose, true), "verbose", Some('v'))
.help("Do dee doo. We're really stretching here HAAAAAAAA HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!"),
)
.add(
Parameter::option(Scalar::new(&mut operand), "operand", Some('o'))
.help("moot")
.choice(Operand::Add, "+")
.choice(Operand::Multiply, "*"),
)
.add(Parameter::option(Optional::new(&mut initial), "initial", None)
.meta(vec!["testing a really long meta.. abcdefghijklmnopqrstuvwxyz"])
)
.add(Parameter::option(Collection::new(&mut _countries, Nargs::AtLeastOne), "country", None))
.add(
Parameter::argument(Collection::new(&mut items, Nargs::AtLeastOne), "item")
.help("The items."),
)
.build();
parser.parse();
println!("Items: {items:?}");
execute(_verbose, operand, initial, _countries, items);
}
examples/foo_bar.rs (line 81)
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
fn main() {
let mut verbose: bool = false;
let mut foo_bar = FooBar::Foo;
let mut initial: Option<u32> = None;
let mut countries: HashSet<Country> = HashSet::default();
let mut items: Vec<u32> = Vec::default();
let ap = CommandLineParser::new("foo_bar");
let parser = ap
.add(
Parameter::option(Switch::new(&mut verbose, true), "verbose", Some('v'))
.help("Do dee doo."),
)
.branch(
Condition::new(Scalar::new(&mut foo_bar), "foo_bar")
.choice(FooBar::Foo, "123 abc let's make this one medium long.")
.choice(FooBar::Bar, "456 def let's make this one multiple sentences. We're really stretching here HAAAAAAAA HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!")
.help("foo'y bar'y stuff")
.meta(vec!["a", "b", "c"]),
)
.command(FooBar::Foo, |sub| {
sub.add(Parameter::option(
Optional::new(&mut initial),
"initial",
None,
))
.add(
Parameter::argument(Collection::new(&mut items, Nargs::Any), "item")
.help("The items."),
)
})
.command(FooBar::Bar, |sub| {
sub.add(Parameter::option(
Collection::new(&mut countries, Nargs::AtLeastOne),
"country",
None,
))
})
.build();
parser.parse();
println!("Items: {items:?}");
execute(verbose, foo_bar, initial, countries, items);
}
Trait Implementations§
impl<'a, C, T> CliArgument for Collection<'a, C, T>where
C: 'a + Collectable<T>,
impl<'a, C, T> CliOption for Collection<'a, C, T>where
C: 'a + Collectable<T>,
Auto Trait Implementations§
impl<'a, C, T> !RefUnwindSafe for Collection<'a, C, T>
impl<'a, C, T> !Send for Collection<'a, C, T>
impl<'a, C, T> !Sync for Collection<'a, C, T>
impl<'a, C, T> Unpin for Collection<'a, C, T>where
T: Unpin,
impl<'a, C, T> !UnwindSafe for Collection<'a, C, 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