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

@OptionSet macro: Choose Your Own Adventure edition #19

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

DougGregor
Copy link
Owner

@DougGregor DougGregor commented Mar 8, 2023

Make the @OptionSet macro simultaneously support three different forms of option set!

Form #1:

@OptionSet<UInt8>
struct ShippingOptions {
  static var nextDay: ShippingOptions
  static var secondDay: ShippingOptions
  static var priority: ShippingOptions
  static var standard: ShippingOptions
}

Form #2:

@OptionSet<UInt8>
struct ShippingOptions {
  enum Options {
    case nextDay
    case secondDay
    case priority
    case standard
  }
}

Form #3:

@OptionSet<UInt8>
enum Options: UInt8 {
  case nextDay
  case secondDay
  case priority
  case standard

  // macro adds a nested type Set that is the option set
}

This implementation uses static vars without initializers to describe
each option, rather than cases of a nested enum, and was suggested
by Joe Groff.
@DougGregor DougGregor changed the title Alternative implementation of option set macro @OptionSet macro: Choose Your Own Adventure edition Mar 16, 2023
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