clap icon indicating copy to clipboard operation
clap copied to clipboard

Lifetime of possible values and PossibleValueParser

Open liningpan opened this issue 1 year ago • 1 comments

Please complete the following tasks

Rust Version

rustc 1.62.1 (e092d0b6b 2022-07-16)

Clap Version

3.2.16

Minimal reproducible code

use clap::{command, Arg};

fn main() {
    let possible_values: Vec<&str> = vec!["abc", "def"];
    let app = command!().arg(Arg::new("example").possible_values(&possible_values));
    let matches = app.get_matches();
    println!("{:#?}", matches);
}

Steps to reproduce the bug with the above code

I'm trying to build a dynamic command line interface, where possible options are read from a config file. This is currently possible as .possible_values() requires 'help lifetime, but the new PossibleValueParser implementation requires 'static lifetime.

Actual Behaviour

N/A

Expected Behaviour

N/A

Additional Context

No response

Debug Output

No response

liningpan avatar Aug 07 '22 16:08 liningpan

We can't add lifetimes to PossibleValueParser without a breaking change and on next breaking change, we're hoping to remove lifetimes completely, see https://github.com/clap-rs/clap/issues/1041.

epage avatar Aug 09 '22 18:08 epage

Resolved in #4097

epage avatar Aug 22 '22 18:08 epage