Skip to content

Lifetimes of App, Arg, ArgGroup: removing or relaxing #1041

Closed
@Rupsbant

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 AParsestruct before creating the App object.

Metadata

Assignees

Labels

A-builderArea: Builder APIC-enhancementCategory: Raise on the bar on expectationsE-mediumCall for participation: Experience needed to fix: Medium / intermediateM-breaking-changeMeta: Implementing or merging this will introduce a breaking change.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions