aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/WireGuardResult.swift
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2018-12-06 16:30:11 +0530
committerRoopesh Chander <roop@roopc.net>2018-12-07 12:36:19 +0530
commit782dd2ea4e4143c8aa78f314cb9a20bbc743b99c (patch)
tree74c0ac40345073a81d2d881acedfec0ba913b864 /WireGuard/WireGuard/WireGuardResult.swift
parentError handling: Introduce a WireGuardAppError protocol to manage errors (diff)
downloadwireguard-apple-782dd2ea4e4143c8aa78f314cb9a20bbc743b99c.tar.xz
wireguard-apple-782dd2ea4e4143c8aa78f314cb9a20bbc743b99c.zip
Error handling: Introduce a WireGuardResult type to handle errors in callbacks across the app
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/WireGuardResult.swift')
-rw-r--r--WireGuard/WireGuard/WireGuardResult.swift28
1 files changed, 28 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/WireGuardResult.swift b/WireGuard/WireGuard/WireGuardResult.swift
new file mode 100644
index 00000000..93fc4c2c
--- /dev/null
+++ b/WireGuard/WireGuard/WireGuardResult.swift
@@ -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
+ }
+ }
+}