mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
docs: use custom error set in values.zig sample.
Signed-off-by: Nashwan Azhari <aznashwan@icloud.com>
This commit is contained in:
parent
153521279f
commit
af7dec94c6
1 changed files with 6 additions and 1 deletions
|
|
@ -4,6 +4,11 @@ const std = @import("std");
|
||||||
const os = std.os;
|
const os = std.os;
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
|
|
||||||
|
// Custom error set definition:
|
||||||
|
const ExampleErrorSet = error{
|
||||||
|
ExampleErrorVariant,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn main() void {
|
pub fn main() void {
|
||||||
// integers
|
// integers
|
||||||
const one_plus_one: i32 = 1 + 1;
|
const one_plus_one: i32 = 1 + 1;
|
||||||
|
|
@ -36,7 +41,7 @@ pub fn main() void {
|
||||||
});
|
});
|
||||||
|
|
||||||
// error union
|
// error union
|
||||||
var number_or_error: anyerror!i32 = error.ArgNotFound;
|
var number_or_error: ExampleErrorSet!i32 = ExampleErrorSet.ExampleErrorVariant;
|
||||||
|
|
||||||
print("\nerror union 1\ntype: {}\nvalue: {!}\n", .{
|
print("\nerror union 1\ntype: {}\nvalue: {!}\n", .{
|
||||||
@TypeOf(number_or_error),
|
@TypeOf(number_or_error),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue