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

Rough cut at enum generation #16

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

Conversation

thomcc
Copy link
Contributor

@thomcc thomcc commented Jun 7, 2021

This branch is forked off of #15, so most of the first commits are from that (githubs UI handles this poorly). I'll rebase after that merges, which will fix the issue. Until then, the last commit of this is actually where the meat is.

This takes a stab at implementing enum support. I think it supports most common uses, although I haven't tested it exhaustively.

That said, it's kind not the best and I'm unsure how I feel about it:

  • The visit_enums thing is probably the wrong approach and likely can be simplified.
  • Ty::Enum is unlike the other Ty variants in a bunch of ways and code usually either
    • ignores all the other Ty variants excapt enum,
    • or wants to treat enum essentially the same as any other FromStr (which it basically is)
  • I'd also vaguely like to have a deduping these.
    • I've had this for things like --format format: text | json | csv.
    • As the code is now you probably can probably hack around this by using the of the enum we generate for all-but-one use, and have most stuff work well (except for docs).
    • A challenge here is that in this patch, the enum always inherits the typename from the field its used for.

I don't know how many of these are worth fixing, and how many are deliberate wontfixes (and how many are worth fixing someday but not urgently). I think it's probably a mix, tbh (I just felt like it was worth writing this stuff out while I still had it).

Anyway, I'm done poking at this at the moment, and figured I'd push it up for now.

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

Successfully merging this pull request may close these issues.

1 participant