aboutsummaryrefslogtreecommitdiff
path: root/src/lib/sysexchange.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/sysexchange.zig')
-rw-r--r--src/lib/sysexchange.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/lib/sysexchange.zig b/src/lib/sysexchange.zig
index 01220b0..0abf7bc 100644
--- a/src/lib/sysexchange.zig
+++ b/src/lib/sysexchange.zig
@@ -15,6 +15,15 @@ pub const Status = enum(usize) {
else => .unknown,
};
}
+
+ // Calling this on the "success" variant is safety-checked
+ // undefined behavior at runtime.
+ pub fn toError(self: Status) anyerror {
+ return switch (self) {
+ .success => unreachable,
+ .unknown => error.Unknown,
+ };
+ }
};
pub fn Result(comptime T: type) type {
@@ -46,6 +55,10 @@ pub fn Result(comptime T: type) type {
},
};
}
+
+ pub fn toErrorUnion(self: Self) !T {
+ return if (self.status == .success) self.value else self.status.toError();
+ }
};
}