Can't parse a Vec<String>
RazrFalcon opened this issue · comments
fn parse_languages(s: &str) -> Result<Vec<String>, &'static str> {
let mut langs = Vec::new();
for lang in s.split(',') {
langs.push(lang.trim().to_string());
}
Ok(langs)
}
// ...
#[options(no_short, meta = "LANG", default = "en", parse(try_from_str = "parse_languages"))]
languages: Vec<String>,
error[E0308]: try expression alternatives have incompatible types
--> src/main.rs:81:17
|
81 | #[derive(Debug, Options)]
| ^^^^^^^
| |
| expected struct `std::string::String`, found struct `std::vec::Vec`
| help: try wrapping with a success variant: `Ok(Options)`
|
= note: expected type `std::string::String`
found type `std::vec::Vec<std::string::String>`
Yes, this is a minor design bug. gumdrop_derive
sees a Vec<T>
field and assumes that it will be expressed as a series of option values of type T
; e.g. -x value0 -x value1 -x value2
.
I'll add a per-field option to disable this automatic behavior.
I've just pushed the commit implementing this option. Adding no_multi
to the field attribute list should solve this issue.
Thanks!