Structopt: Possible values

Created on 12 Aug 2018  路  3Comments  路  Source: TeXitoi/structopt

Hello all,

I still do not understand why the following code does not compile:

lazy_static! {
    static ref PV: Vec<&'static str> = vec!["abc", "def"];
}

#[derive(StructOpt)]
pub struct CustomArg {
    #[structopt(name = "mode",  possible_values = "&PV")]
    mode: String,
}

the compiler complains:

error[E0308]: mismatched types                   
  --> src\main.rs:76:10                          
   |                                             
76 | #[derive(StructOpt)]                        
   |          ^^^^^^^^^ expected slice, found str
   |                                             
   = note: expected type `&[&str]`               
              found type `&'static str`          

Looking around, I found a similar issue with a suggestion that possible_values should be replaced by possible_values_raw. But when I use possible_values_raw, the compiler complains:

error[E0599]: no method named `possible_values_raw` found for type `structopt::clap::Arg<'_, '_>` in the current scope
  --> src\main.rs:76:10
   |
76 | #[derive(StructOpt)]
   |          ^^^^^^^^^
   |
   = help: did you mean `possible_values`?

Many thanks for any response.

Most helpful comment

Thats now raw(possible_values = "&PV")

All 3 comments

Thats now raw(possible_values = "&PV")

Many thanks @TeXitoi . It compiles now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tathanhdinh picture tathanhdinh  路  6Comments

bb010g picture bb010g  路  9Comments

sphynx picture sphynx  路  9Comments

polarathene picture polarathene  路  6Comments

sharksforarms picture sharksforarms  路  6Comments