Skip to content
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.

Consider accepting a Cow instead of Into<&'b str> in App::about #166

Open
epage opened this issue Dec 6, 2021 · 4 comments
Open

Consider accepting a Cow instead of Into<&'b str> in App::about #166

epage opened this issue Dec 6, 2021 · 4 comments

Comments

@epage
Copy link
Owner

epage commented Dec 6, 2021

Issue by d-e-s-o
Sunday Oct 04, 2020 at 18:26 GMT
Originally opened as clap-rs/clap#2150


I find the signature of methods like App::about not super useful. It's probably fine when doing everything statically, because you could easily make sure that the string provided outlives the App object (because most of the time you have a 'static string anyway as everything is defined statically in the code). But consider the case where you'd want to add subcommands dynamically at runtime. It gets unnecessarily unwieldy now, in my opinion, because of the lifetime requirement.

Couldn't you instead accept a Cow<'b, str>? This way, users that do something more dynamic would at least have the possibility to fudge that with a dynamic memory allocation at the call site, instead of doing some dance to make the generated string outlive the App object or even boxing the string up just to leak it.

@epage
Copy link
Owner Author

epage commented Dec 6, 2021

Comment by ldm0
Tuesday Oct 06, 2020 at 01:00 GMT


Related: clap-rs/clap#1728

@epage
Copy link
Owner Author

epage commented Dec 6, 2021

Comment by pksunkara
Wednesday May 26, 2021 at 14:40 GMT


@d-e-s-o Do you think you can take a small attempt at this by only changing the about? Would like to see how it improves the API.

@epage
Copy link
Owner Author

epage commented Dec 6, 2021

Comment by d-e-s-o
Thursday May 27, 2021 at 16:08 GMT


@d-e-s-o Do you think you can take a small attempt at this by only changing the about? Would like to see how it improves the API.

Sure, see clap-rs/clap#2504.

@epage
Copy link
Owner Author

epage commented Dec 6, 2021

Comment by epage
Monday Oct 04, 2021 at 17:53 GMT


This is related to my proposed fix for #1041

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant