Error handling: Introduce a WireGuardResult type to handle errors in callbacks across the app

Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
Roopesh Chander
2018-12-06 16:30:11 +05:30
parent c9267ba634
commit 782dd2ea4e
3 changed files with 34 additions and 28 deletions
+28
View File
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
// Copyright © 2018 WireGuard LLC. All Rights Reserved.
enum WireGuardResult<T> {
case success(T)
case failure(WireGuardAppError)
var value: T? {
switch (self) {
case .success(let v): return v
case .failure(_): return nil
}
}
var error: WireGuardAppError? {
switch (self) {
case .success(_): return nil
case .failure(let e): return e
}
}
var isSuccess: Bool {
switch (self) {
case .success(_): return true
case .failure(_): return false
}
}
}