Skip to content

Commit

Permalink
Add OptionSet extension
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Jan 10, 2025
1 parent 1134dbc commit 72b61a7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Sources/GATT/Extensions/OptionSet.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// OptionSet.swift
// GATT
//
// Created by Alsey Coleman Miller on 1/10/25.
//

extension OptionSet {
@inline(never)
internal func buildDescription(
_ descriptions: [(Element, StaticString)]
) -> String {
var copy = self
var result = "["

for (option, name) in descriptions {
if _slowPath(copy.contains(option)) {
result += name.description
copy.remove(option)
if !copy.isEmpty { result += ", " }
}
}

if _slowPath(!copy.isEmpty) {
result += "\(Self.self)(rawValue: \(copy.rawValue))"
}
result += "]"
return result
}
}

0 comments on commit 72b61a7

Please sign in to comment.