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.
I've been working on supporting enum variants (#23) (currently only named enum variants have any progress) with the
#[builder]
proc-macro in bon. While I've made progress, there are a couple of issues and limitations I'm stuck on and would appreciate some guidance/help.Issues:
EnumVariantBuilder
struct twice . The builder implementation, however, is only defined once.#[builder]
macro on an enum, the original enum definition disappears from the expanded code. This can be bypassed by defining the enum twice, but this is a hack.Example Code
This code results in the strange behavior mentioned above. Defining the enum twice allows compilation:
Limitations
No generics support currently: The current implementation doesn't support generics for enums. I'm unsure how to approach defining minimal generics (mainly bounds) for the enum variants. My idea is to introduce a new attribute like
bon(bound = "...")
, similar toserde(bound = "...")
. (which is obviously up for discussion)Customization of the generated struct is disabled : Currently, customizing the generated struct is not supported. This is due to the
StructInputParms
struct encountering an error when usingfrom_meta::from_list
on enum variants, as it returns an error, which has a gist of unknown fieldBinary
.Total Generated Code from latest commit