These are chat archives for kbknapp/clap-rs

20th
Feb 2017
Niklas Claesson
@NickeZ
Feb 20 2017 21:20
Hey, I have a problem I can't figure out
warning: unreachable pattern, #[warn(unreachable_patterns)] on by default
   --> src/options.rs:103:27
    |
103 |         options.command = values_t!(matches, "command", String).expect("Argument 'command' missing");
    |                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this error originates in a macro outside of the current crate

warning: unreachable pattern, #[warn(unreachable_patterns)] on by default
   --> src/options.rs:117:28
    |
117 |         if let Ok(bindv) = values_t!(matches, "bind", String) {
    |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: this error originates in a macro outside of the current crate
why do I get unreachable pattern?
Kevin K.
@kbknapp
Feb 20 2017 21:38
Interesting, could you file an issue, and if possible could you post the surrounding code?
Kevin K.
@kbknapp
Feb 20 2017 21:39
Although, if you want a string, you don't need to use that macro
Niklas Claesson
@NickeZ
Feb 20 2017 21:39
I want vec<String>
Kevin K.
@kbknapp
Feb 20 2017 21:40
Ah ok then that's probably why
Niklas Claesson
@NickeZ
Feb 20 2017 21:40
I don't get it, what am I doing wrong?
Kevin K.
@kbknapp
Feb 20 2017 21:43
I'm on mobile right now, so I can't type it out easily, but also for a Vec<String> you still don't need a macro. You can do let v: Vec<String> = matches.values_of("command").collect();
I'll check it once I'm at my computer and get back a more detailed answer or verify a bug and let you know ;)
Oops, I'm missing an .unwrap()
Niklas Claesson
@NickeZ
Feb 20 2017 21:46
cool, yeah this solves the problem, thanks!
Kevin K.
@kbknapp
Feb 20 2017 21:47
No problem!
Niklas Claesson
@NickeZ
Feb 20 2017 21:48
it is not 100% happy with one of my lines. Should I keep &str instead of String?
error[E0277]: the trait bound `std::vec::Vec<std::string::String>: std::iter::FromIterator<&str>` is not satisfied
   --> src/options.rs:103:93
    |
103 |         options.command = matches.values_of("command").expect("Argument 'command' missing").collect();
    |                                                                                             ^^^^^^^ the trait `std::iter::FromIterator<&str>` is not implemented for `std::vec::Vec<std::string::String>`
    |
    = note: a collection of type `std::vec::Vec<std::string::String>` cannot be built from an iterator over elements of type `&str`
I could do .map(|x| String::from(x)).collect. Not sure if this is the best though
Niklas Claesson
@NickeZ
Feb 20 2017 21:54
Did you want me to create an issue or is my original problem not really a problme?
Kevin K.
@kbknapp
Feb 20 2017 21:56
You can shorten it to .map(String::from).collect()
Niklas Claesson
@NickeZ
Feb 20 2017 21:57
I'm currently exploring if I can keep a &'static str around instead of Strings
then it is fine to do simply .collect()
Kevin K.
@kbknapp
Feb 20 2017 21:58
If the ArgMatches struct will be alive for the whole time you need it, you can use a slice. Otherwise I'd use a String
Niklas Claesson
@NickeZ
Feb 20 2017 22:00
OK, I'll go with String.