Skip to content

Commit

Permalink
Add Sendable conformance
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Sep 26, 2023
1 parent 9b0a2d0 commit 686f941
Show file tree
Hide file tree
Showing 18 changed files with 35 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Sources/Bluetooth/Address.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

/// Bluetooth address.
@frozen
public struct BluetoothAddress: ByteValue {
public struct BluetoothAddress: ByteValue, Sendable {

// MARK: - ByteValueType

Expand Down
4 changes: 4 additions & 0 deletions Sources/Bluetooth/BitMaskOption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public struct BitMaskOptionSet <Element: BitMaskOption>: RawRepresentable {
}
}

// MARK: - Sendable

extension BitMaskOptionSet: Sendable where RawValue: Sendable { }

// MARK: - Sequence Conversion

public extension BitMaskOptionSet {
Expand Down
19 changes: 1 addition & 18 deletions Sources/Bluetooth/BluetoothUUID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

/// Bluetooth UUID
@frozen
public enum BluetoothUUID: Equatable {
public enum BluetoothUUID: Equatable, Hashable, Sendable {

case bit16(UInt16)
case bit32(UInt32)
Expand Down Expand Up @@ -39,23 +39,6 @@ extension BluetoothUUID: CustomStringConvertible {
}
}

// MARK: - Hashable

extension BluetoothUUID: Hashable {

public func hash(into hasher: inout Hasher) {

switch self {
case let .bit16(value):
return value.hash(into: &hasher)
case let .bit32(value):
return value.hash(into: &hasher)
case let .bit128(value):
return value.hash(into: &hasher)
}
}
}

// MARK: - RawRepresentable

extension BluetoothUUID: RawRepresentable {
Expand Down
41 changes: 15 additions & 26 deletions Sources/Bluetooth/ClassOfDevice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public struct ClassOfDevice: Equatable {
public struct ClassOfDevice: Equatable, Sendable {

internal static let length = 3

Expand Down Expand Up @@ -100,7 +100,7 @@ public struct ClassOfDevice: Equatable {

extension ClassOfDevice {

public struct FormatType: RawRepresentable, Equatable, Hashable {
public struct FormatType: RawRepresentable, Equatable, Hashable, Sendable {

public static let min = FormatType(0b00)

Expand All @@ -109,23 +109,20 @@ extension ClassOfDevice {
public let rawValue: UInt8

public init?(rawValue: UInt8) {

guard rawValue <= type(of: self).max.rawValue, rawValue >= type(of: self).min.rawValue
else { return nil }

self.rawValue = rawValue
}

private init(_ unsafe: UInt8) {

self.rawValue = unsafe
}
}
}

public extension ClassOfDevice {

enum MajorServiceClass: UInt16, BitMaskOption {
enum MajorServiceClass: UInt16, BitMaskOption, Sendable {

/// Limited Discoverable Mode [Ref #1]
case limitedDiscoverable = 0b01
Expand Down Expand Up @@ -170,7 +167,7 @@ public extension ClassOfDevice {

public extension ClassOfDevice {

enum MajorDeviceClass: Equatable {
enum MajorDeviceClass: Equatable, Sendable {

/// Miscellaneous
case miscellaneous
Expand Down Expand Up @@ -273,7 +270,7 @@ public extension ClassOfDevice {
}
}

enum MajorDeviceClassType: UInt8 {
enum MajorDeviceClassType: UInt8, Sendable {

/// Miscellaneous
case miscellaneous = 0b00
Expand Down Expand Up @@ -328,7 +325,7 @@ public extension ClassOfDevice {

public extension ClassOfDevice.MinorDeviceClass {

enum Computer: UInt8 {
enum Computer: UInt8, Sendable {

/// Uncategorized
case uncategorized = 0b00
Expand Down Expand Up @@ -358,7 +355,7 @@ public extension ClassOfDevice.MinorDeviceClass {

public extension ClassOfDevice.MinorDeviceClass {

enum Phone: UInt8 {
enum Phone: UInt8, Sendable {

/// Uncategorized, code for device not assigned
case uncategorized = 0b00
Expand All @@ -382,7 +379,7 @@ public extension ClassOfDevice.MinorDeviceClass {

public extension ClassOfDevice.MinorDeviceClass {

enum NetworkAccessPoint: UInt8 {
enum NetworkAccessPoint: UInt8, Sendable {

/// Fully available
case fullyAvailable = 0b00
Expand Down Expand Up @@ -412,7 +409,7 @@ public extension ClassOfDevice.MinorDeviceClass {

public extension ClassOfDevice.MinorDeviceClass {

enum AudioVideo: UInt8 {
enum AudioVideo: UInt8, Sendable {

/// Uncategorized, code not assigned
case uncategorized = 0b00
Expand Down Expand Up @@ -469,7 +466,7 @@ public extension ClassOfDevice.MinorDeviceClass {

public extension ClassOfDevice.MinorDeviceClass {

enum PeripheralKeyboardPointing: UInt8 {
enum PeripheralKeyboardPointing: UInt8, Sendable {

/// Not Keyboard / Not Pointing Device
case notKeyboard = 0b00
Expand All @@ -484,7 +481,7 @@ public extension ClassOfDevice.MinorDeviceClass {
case comboKeyboardPointingDevice = 0b11
}

enum PeripheralDevice: UInt8 {
enum PeripheralDevice: UInt8, Sendable {

/// Uncategorized device
case uncategorized = 0b00
Expand Down Expand Up @@ -520,7 +517,7 @@ public extension ClassOfDevice.MinorDeviceClass {

public extension ClassOfDevice.MinorDeviceClass {

enum Imaging: UInt8, BitMaskOption {
enum Imaging: UInt8, BitMaskOption, Sendable, CaseIterable {

/// Uncategorized
case uncategorized = 0b00
Expand All @@ -536,20 +533,12 @@ public extension ClassOfDevice.MinorDeviceClass {

/// Printer
case printer = 0b1000

public static let allCases: [ClassOfDevice.MinorDeviceClass.Imaging] = [
.uncategorized,
.display,
.camera,
.scanner,
.printer
]
}
}

public extension ClassOfDevice.MinorDeviceClass {

enum Wearable: UInt8 {
enum Wearable: UInt8, Sendable {

/// Uncategorized
case uncategorized = 0b00
Expand All @@ -573,7 +562,7 @@ public extension ClassOfDevice.MinorDeviceClass {

public extension ClassOfDevice.MinorDeviceClass {

enum Toy: UInt8 {
enum Toy: UInt8, Sendable {

/// Uncategorized
case uncategorized = 0b00
Expand All @@ -597,7 +586,7 @@ public extension ClassOfDevice.MinorDeviceClass {

public extension ClassOfDevice.MinorDeviceClass {

enum Health: UInt8 {
enum Health: UInt8, Sendable {

/// Uncategorized
case uncategorized = 0b00
Expand Down
2 changes: 1 addition & 1 deletion Sources/Bluetooth/CompanyIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
///
/// - SeeAlso: [Company Identifiers](https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers)
@frozen
public struct CompanyIdentifier: RawRepresentable, Equatable, Hashable {
public struct CompanyIdentifier: RawRepresentable, Equatable, Hashable, Sendable {

public var rawValue: UInt16

Expand Down
2 changes: 1 addition & 1 deletion Sources/Bluetooth/LowEnergyAdvertisingData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
///
/// ![Image](https://github.com/PureSwift/Bluetooth/raw/master/Assets/LowEnergyAdvertisingDataExample1.png)
@frozen
public struct LowEnergyAdvertisingData {
public struct LowEnergyAdvertisingData: Sendable {

// MARK: - ByteValue

Expand Down
2 changes: 1 addition & 1 deletion Sources/Bluetooth/LowEnergyScanTimeInterval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/// Time = N * 0.625 msec
/// Time Range: 2.5 msec to 10240 msec
@frozen
public struct LowEnergyScanTimeInterval: RawRepresentable, Equatable, Comparable, Hashable {
public struct LowEnergyScanTimeInterval: RawRepresentable, Equatable, Comparable, Hashable, Sendable {

/// 2.5 msec
public static let min = LowEnergyScanTimeInterval(0x0004)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Bluetooth/RSSI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/// Range: -127 ≤ N ≤ +20
/// Units: dBm
@frozen
public struct RSSI: RawRepresentable, Equatable, Hashable {
public struct RSSI: RawRepresentable, Equatable, Hashable, Sendable {

/// Units: dBm
public let rawValue: Int8
Expand Down
2 changes: 1 addition & 1 deletion Sources/Bluetooth/SFloat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public extension Float16 {

/// IEEE-11073 16-bit SFLOAT
@frozen
public struct SFloat: Equatable, Hashable, Codable {
public struct SFloat: Equatable, Hashable, Codable, Sendable {

/// The bit pattern of the value’s encoding.
public private(set) var bitPattern: UInt16
Expand Down
2 changes: 1 addition & 1 deletion Sources/Bluetooth/SecurityLevel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

/// Bluetooth security level.
public enum SecurityLevel: UInt8 {
public enum SecurityLevel: UInt8, Sendable {

case sdp = 0
case low = 1
Expand Down
2 changes: 1 addition & 1 deletion Sources/Bluetooth/UInt128.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
///
/// Unlike `NSUUID` which is always stored in big endian.
@frozen
public struct UInt128: ByteValue {
public struct UInt128: ByteValue, Sendable {

public typealias ByteValue = (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Bluetooth/UInt24.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

/// A 24 bit number stored according to host endianness.
@frozen
public struct UInt24: ByteValue {
public struct UInt24: ByteValue, Sendable {

public typealias ByteValue = (UInt8, UInt8, UInt8)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Bluetooth/UInt256.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

/// A 256 bit number stored according to host endianness.
@frozen
public struct UInt256: ByteValue {
public struct UInt256: ByteValue, Sendable {

public typealias ByteValue = (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Bluetooth/UInt40.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

/// A 40 bit number stored according to host endianness.
@frozen
public struct UInt40: ByteValue {
public struct UInt40: ByteValue, Sendable {

public typealias ByteValue = (UInt8, UInt8, UInt8, UInt8, UInt8)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Bluetooth/UInt48.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

@frozen
public struct UInt48: ByteValue {
public struct UInt48: ByteValue, Sendable {

public typealias ByteValue = (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)

Expand Down
2 changes: 1 addition & 1 deletion Sources/Bluetooth/UInt512.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

/// A 512 bit number stored according to host endianness.
@frozen
public struct UInt512: ByteValue {
public struct UInt512: ByteValue, Sendable {

public typealias ByteValue = (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)

Expand Down
4 changes: 1 addition & 3 deletions Sources/Bluetooth/UnitIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
import Foundation

@frozen
public struct UnitIdentifier: RawRepresentable, Equatable, Hashable {
public struct UnitIdentifier: RawRepresentable, Equatable, Hashable, Sendable {

public var rawValue: UInt16

public init(rawValue: UInt16) {

self.rawValue = rawValue
}
}
Expand All @@ -24,7 +23,6 @@ public struct UnitIdentifier: RawRepresentable, Equatable, Hashable {
extension UnitIdentifier: ExpressibleByIntegerLiteral {

public init(integerLiteral value: UInt16) {

self.init(rawValue: value)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Bluetooth/iBeacon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
- SeeAlso: [Getting Started with iBeacon](https://developer.apple.com/ibeacon/Getting-Started-with-iBeacon.pdf).
*/
@frozen
public struct AppleBeacon: Equatable, Hashable {
public struct AppleBeacon: Equatable, Hashable, Sendable {

#if !os(WASI)
/// The company that created this specification.
Expand Down

0 comments on commit 686f941

Please sign in to comment.