| ... | @@ -4,6 +4,11 @@ const std = @import("std"); | ... | @@ -4,6 +4,11 @@ const std = @import("std"); |
| 4 | const os = std.os; | 4 | const os = std.os; |
| 5 | const assert = std.debug.assert; | 5 | const assert = std.debug.assert; |
| 6 | | 6 | |
| | 7 | // Custom error set definition: |
| | 8 | const ExampleErrorSet = error{ |
| | 9 | ExampleErrorVariant, |
| | 10 | }; |
| | 11 | |
| 7 | pub fn main() void { | 12 | pub fn main() void { |
| 8 | // integers | 13 | // integers |
| 9 | const one_plus_one: i32 = 1 + 1; | 14 | const one_plus_one: i32 = 1 + 1; |
| ... | @@ -36,7 +41,7 @@ pub fn main() void { | ... | @@ -36,7 +41,7 @@ pub fn main() void { |
| 36 | }); | 41 | }); |
| 37 | | 42 | |
| 38 | // error union | 43 | // error union |
| 39 | var number_or_error: anyerror!i32 = error.ArgNotFound; | 44 | var number_or_error: ExampleErrorSet!i32 = ExampleErrorSet.ExampleErrorVariant; |
| 40 | | 45 | |
| 41 | print("\nerror union 1\ntype: {}\nvalue: {!}\n", .{ | 46 | print("\nerror union 1\ntype: {}\nvalue: {!}\n", .{ |
| 42 | @TypeOf(number_or_error), | 47 | @TypeOf(number_or_error), |