aboutsummaryrefslogtreecommitdiff
path: root/lib/std/meta.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-25 13:27:44 -0400
committerGitHub <noreply@github.com>2021-04-25 13:27:44 -0400
commit6f61594692af846226880e5903ad26a922014d55 (patch)
tree4524089b8c9cc6c69c65a73cf20380a66fcc29be /lib/std/meta.zig
parent5a94794b73c8f9d042bc7928d071cc1004487983 (diff)
parent89c41f30c3e62e8b5c03457d1f95dc115a27ef15 (diff)
downloadzig-6f61594692af846226880e5903ad26a922014d55.tar.gz
zig-6f61594692af846226880e5903ad26a922014d55.zip
Merge pull request #8496 from xackus/isError
std.meta: add isError
Diffstat (limited to 'lib/std/meta.zig')
-rw-r--r--lib/std/meta.zig10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/std/meta.zig b/lib/std/meta.zig
index c6f800ca2c..dd6f500076 100644
--- a/lib/std/meta.zig
+++ b/lib/std/meta.zig
@@ -1346,3 +1346,13 @@ test "shuffleVectorIndex" {
testing.expect(shuffleVectorIndex(6, vector_len) == -3);
testing.expect(shuffleVectorIndex(7, vector_len) == -4);
}
+
+/// Returns whether `error_union` contains an error.
+pub fn isError(error_union: anytype) bool {
+ return if (error_union) |_| false else |_| true;
+}
+
+test "isError" {
+ std.testing.expect(isError(math.absInt(@as(i8, -128))));
+ std.testing.expect(!isError(math.absInt(@as(i8, -127))));
+}