diff options
| author | xackus <14938807+xackus@users.noreply.github.com> | 2021-04-11 16:26:29 +0200 |
|---|---|---|
| committer | xackus <14938807+xackus@users.noreply.github.com> | 2021-04-11 16:26:29 +0200 |
| commit | a5007d819a0bd4d247602786a36cabae821f52b9 (patch) | |
| tree | 6d43960f769b8f5375f07aa9bdffd4b8e25e0d43 /lib/std/meta.zig | |
| parent | cab1d5c1a320239af5be88571d7989ba230b90be (diff) | |
| download | zig-a5007d819a0bd4d247602786a36cabae821f52b9.tar.gz zig-a5007d819a0bd4d247602786a36cabae821f52b9.zip | |
std.meta: add isError
Diffstat (limited to 'lib/std/meta.zig')
| -rw-r--r-- | lib/std/meta.zig | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/std/meta.zig b/lib/std/meta.zig index 860b6874c0..122e644bf3 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -1334,3 +1334,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)))); +} |
