Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please implement impl From<Cow<'static, str>> for StyledStr #5785

Open
2 tasks done
teythoon opened this issue Oct 22, 2024 · 4 comments
Open
2 tasks done

Please implement impl From<Cow<'static, str>> for StyledStr #5785

teythoon opened this issue Oct 22, 2024 · 4 comments
Labels
A-builder Area: Builder API C-enhancement Category: Raise on the bar on expectations E-easy Call for participation: Experience needed to fix: Easy / not much

Comments

@teythoon
Copy link

Please complete the following tasks

Clap Version

4.5.20

Describe your use case

We have a type representing a group of arguments that we can #[command(flatten)] into a number of subcommands. We want to tweak the help texts for some of them, but most will use the default help text. The default help text is a &'static str, but the tweaked versions would have to be heap allocated. Now, we'd like to avoid the heap allocations for the vast majority of help texts.

Describe the solution you'd like

We'd like to use Arg::new(..).help(maybe_modify("the default help text")) where maybe_modify returns a Cow<'static, str>.

Alternatives, if applicable

The alternative is to heap allocate even the help texts we don't want to change, i.e. do Arg::new(..).help(maybe_modify("the default help text")) where maybe_modify returns a String. This works today, but meh.

Additional Context

No response

@teythoon teythoon added the C-enhancement Category: Raise on the bar on expectations label Oct 22, 2024
@epage epage added A-builder Area: Builder API E-easy Call for participation: Experience needed to fix: Easy / not much labels Oct 22, 2024
@epage
Copy link
Member

epage commented Oct 22, 2024

I'm fine with someone posting a PR for this. If we have other places where there is a From from either 'static or owned, we should add it there as well.

Note: this could be worked around instead by having maybe_modify return a StyledStr and then you can call the separate Froms for each case.

@teythoon
Copy link
Author

Returning StyledStr is a good idea in the mean time, thanks!

@zaira-bibi
Copy link

Hey! I'd like to try my hand at this please.

@zaira-bibi
Copy link

Hi @epage, I've opened a PR for this issue. I'm not sure where I was supposed to write the tests for this, so guidance in that would really be appreciated. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-builder Area: Builder API C-enhancement Category: Raise on the bar on expectations E-easy Call for participation: Experience needed to fix: Easy / not much
Projects
None yet
Development

No branches or pull requests

3 participants