Last active
June 11, 2026 20:19
-
-
Save natecook1000/6aab5c755a350f356b0d8c48c551914c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// A guaranteed-sendable regex type. | |
| struct SendableRegex<Output>: RegexComponent, @unchecked Sendable { | |
| let regex: Regex<Output> | |
| init?(_ re: some RegexComponent<Output>) { | |
| if nil == re.regex._literalPattern { return nil } | |
| self.regex = re.regex | |
| } | |
| } | |
| // Usage: | |
| import RegexBuilder | |
| let simpleRegex = #/a+b*c/# | |
| let complexRegex = Regex { | |
| OneOrMore { "a" } | |
| ZeroOrMore { "b" } | |
| TryCapture { | |
| OneOrMore(.digit) | |
| } transform: { | |
| Int($0) | |
| } | |
| } | |
| let sendableRegex = SendableRegex(simpleRegex) // ok | |
| let nonSendableRegex = SendableRegex(complexRegex) // nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment