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

Support _variant in outer level enum formatting for Display #377

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JelteF
Copy link
Owner

@JelteF JelteF commented Jul 2, 2024

Resolves #142
Resolves #239

Synopsis

This adds back support for top-level format strings of the Display derive. It
now includes the display of the variant whenever the _variant placeholder
apears be found. It also supports using the field

Solution

This does not include the same support for Debug, since it is considered much less
useful there and the differences between the Debug implementation and Display
implementation make it a non-trivial port.

Only named arguments are supported in the format string, no positional ones.
This made the implementation easier, maybe in a future PR positional support
can be added.

This bumps MSRV to 1.70.0, on earlier versions the derived code throws the following error:

error: there is no argument named `_0`
    --> tests/display.rs:1373:26
     |
1373 |                 #[derive(Display)]
     |                          ^^^^^^^
     |
     = note: did you intend to capture a variable `_0` from the surrounding scope?
     = note: to avoid ambiguity, `format_args!` cannot capture variables when the format string is expanded from a macro
     = note: this error originates in the derive macro `Display` (in Nightly builds, run with -Z macro-backtrace for more info)

Checklist

  • Documentation is updated (if required)
  • Tests are added/updated (if required)
  • CHANGELOG entry is added (if required)

@JelteF JelteF added this to the 1.0.0 milestone Jul 2, 2024
@JelteF JelteF requested a review from tyranron July 2, 2024 10:44
@JelteF JelteF self-assigned this Jul 2, 2024
@JelteF JelteF force-pushed the outer-level-enum-formatting branch 3 times, most recently from da56134 to 734ed21 Compare July 2, 2024 11:35
@JelteF
Copy link
Owner Author

JelteF commented Jul 2, 2024

Still needs some cleanup, error-ing on edge cases, and updated docs, but the general design seems to work.

@JelteF JelteF force-pushed the outer-level-enum-formatting branch 8 times, most recently from 0573f07 to cf2c6bf Compare July 3, 2024 12:39
@JelteF
Copy link
Owner Author

JelteF commented Jul 3, 2024

Still needs some cleanup, error-ing on edge cases, and updated docs, but the general design seems to work.

Okay all done now, this is ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant