Support deriving Parser
on struct with lifetime and automatically parse Cow<'_, T>
into Cow::Owned
#5773
Labels
A-derive
Area: #[derive]` macro API
C-enhancement
Category: Raise on the bar on expectations
E-hard
Call for participation: Experience needed to fix: Hard / a lot
Please complete the following tasks
Clap Version
v4.5.19
Describe your use case
Currently, as investigated and discussed in #5772, it seems impossible to derive
Parser
on a struct that has fields withCow<'_, T>
where the lifetime isn't'static
.This happens, e.g., when one wants to reuse the same code to both create CLI and also structure available in the public API of the crate. E.g., see code below (that does not compile):
Describe the solution you'd like
When parsing from args, Clap should be capable to choose the
Cow::Owned
variant, and not care about the lifetime duration of the fields.Moreover, it would be nice that Clap provides a default parser for
Cow<'_, T>
if<T as ToOwned>::Owned
is a type that could be parsed automatically be Clap.Alternatives, if applicable
The only alternative I think of is currently to create a new structure, e.g.,
CliOwned
, deriveParser
on it, and implementFrom<CliOwned> for Cli
, but this possibly means a lot of duplicate code, especially documentation strings that I prefer to reuse to avoid errors when copy/pasting.Additional Context
No response
The text was updated successfully, but these errors were encountered: