Skip to content

Replace BitMaskOptionSet with OptionSet#184

Closed
zunda-pixel wants to merge 10 commits into
PureSwift:masterfrom
zunda-pixel:apply-optionset
Closed

Replace BitMaskOptionSet with OptionSet#184
zunda-pixel wants to merge 10 commits into
PureSwift:masterfrom
zunda-pixel:apply-optionset

Conversation

@zunda-pixel
Copy link
Copy Markdown
Contributor

Issue

Fixes #139

What does this PR Do?

Remove BitMaskOption and BitMaskOptionSet and replace with OptionSet.

@zunda-pixel zunda-pixel changed the title Apply optionset Replace BitMaskOptionSet with OptionSet May 20, 2025
@zunda-pixel zunda-pixel marked this pull request as ready for review May 20, 2025 05:56
@zunda-pixel zunda-pixel marked this pull request as draft May 20, 2025 06:51
@zunda-pixel
Copy link
Copy Markdown
Contributor Author

zunda-pixel commented May 31, 2025

note: OptionSet Macro has overflow problem.
I will try to use BigUInt.
https://github.com/attaswift/BigInt/

@attached(member, names: named(RawValue), named(rawValue), named(`init`), arbitrary)
@attached(extension, conformances: OptionSet)
public macro OptionSet<RawType>() = #externalMacro(module: "SwiftMacros", type: "OptionSetMacro")


@OptionSet<UInt8>
struct Parameters {
  enum Options: UInt8 {
    case p0 = 0
    case p7 = 7
    case p8 = 8
    case p9 = 9
  }
}

print(Parameters.p0.rawValue) // 2^0 = 1
print(Parameters.p7.rawValue) // 2^7 = 128
print(Parameters.p8.rawValue) // 2^8 = 0(overflow)
print(Parameters.p9.rawValue) // 2^9 = 0(overflow)

@zunda-pixel
Copy link
Copy Markdown
Contributor Author

I think OptionSet has rawValue but it should be have meaning.
Enum (be conforming BitMaskOptionSet)'s rawValue has meaning. I think we can replace to OptionSet.

@zunda-pixel zunda-pixel closed this Jun 1, 2025
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.

Replace BitMaskOptionSet with OptionSet

1 participant