-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathError.swift
More file actions
55 lines (44 loc) · 1.32 KB
/
Error.swift
File metadata and controls
55 lines (44 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors.
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//
/// BTstack Error Code
public struct BTStackError: Error, RawRepresentable, Equatable, Hashable, Sendable {
public let rawValue: Int32
public init(rawValue: Int32) {
self.rawValue = rawValue
}
}
public extension BTStackError {
init(_ hci: HCIError) {
self.init(rawValue: Int32(hci.rawValue))
}
}
public extension HCIError {
init?(_ error: BTStackError) {
guard error.rawValue <= UInt8.max else {
return nil
}
self.init(rawValue: UInt8(error.rawValue))
}
}
internal extension CInt {
func throwsError() throws(BTStackError) {
guard self == 0 else {
throw BTStackError(rawValue: self)
}
}
}
internal extension UInt8 {
func throwsError() throws(BTStackError) {
guard self == 0 else {
throw BTStackError(rawValue: numericCast(self))
}
}
}