Add a format_fallback
method for printing fallback values in the --help
output with a custom formatting function
#411
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, hope you don't mind the unsolicited feature PR! I just started using
bpaf
for a project (I really appreciate your support for parsingenum
s), and discovered that I wanted the ability to print out fallback values using a custom formatting function:You can get the same effect in
bpaf
today by using mapping into and out of a struct with a customDisplay
impl, but it's much clunkier; you have to create a separate struct, provide it the relevant display instance, and map into and out of it, plus you have to manually wrap the fallback value.Also, because the type of
PathBuf::display
is(&self) -> Display<'_>
, we can't simply map into that type, as it doesn't live long enough, and we can't specify it in some sort of "displayPathBuf
s asDisplay
" because we can't provide a lifetime.I also added some documentation for the docs2 crate since I had trouble finding out how to regenerate the docs until I found an old comment of yours.
I think this PR should have everything needed for the change:
bpaf
to support the newformat_fallback
methods on bothParseFallback
andParseFallbackWith
;bpaf_derive
to support usingformat_fallback
in attributes;format_fallback
;format_fallback
; andformat_fallback
alongsidedisplay_fallback
anddebug_fallback
.The only exception is that I didn't include any changelog or version number updates because I wasn't sure how you handled those, but I'm happy to add them too!