Lifetimes of App, Arg, ArgGroup: removing or relaxing #1041
Closed
Description
Affected Version of clap
All 2.x. Breaking API change
Expected Behavior Summary
I want to decouple groups of options to several structs. I want to have a pair functions: one that adds arguments to an App with generated names, one that generates a structure with the added arguments.
Actual Behavior Summary
Uncompilable: the types don't allow to create String in a function and return a borrow.
Sample code
struct A {
...
}
impl A {
fn arguments<'a, 'b>(prefix: &str) -> Vec<Arg<'a, 'b>> {
let name = format!("{}.name", prefix);
...
}
}
Proposed solution
Since clap is dependent on its speed it's probably not an option to force 'String' instead of '&str'. However I think Cow should give enough options.
Alternative for me
Create a struct AParse
to contain the owned strings, split the function arguments
in two parts. A can generate an AParse
struct before creating the App object.