Unknown state [2025-08-04]
This commit is contained in:
11
glfw-vulkan/scratch/defer.zig
Normal file
11
glfw-vulkan/scratch/defer.zig
Normal file
@@ -0,0 +1,11 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() !void {
|
||||
var i: usize = 0;
|
||||
while (i < 10) {
|
||||
i += 1;
|
||||
if (i % 2 == 0)
|
||||
continue;
|
||||
std.debug.print("foo {d}\n", .{i});
|
||||
}
|
||||
}
|
8
glfw-vulkan/scratch/goto.zig
Normal file
8
glfw-vulkan/scratch/goto.zig
Normal file
@@ -0,0 +1,8 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn main() void {
|
||||
acquire: while (true) {
|
||||
continue :acquire;
|
||||
break :acquire;
|
||||
}
|
||||
}
|
42
glfw-vulkan/scratch/switch.zig
Normal file
42
glfw-vulkan/scratch/switch.zig
Normal file
@@ -0,0 +1,42 @@
|
||||
const std = @import("std");
|
||||
|
||||
const Data = enum { foo, bar };
|
||||
|
||||
pub fn optional_enum_error_union() !?Data {
|
||||
const state = struct {
|
||||
var flag: u2 = 0;
|
||||
};
|
||||
defer state.flag +%= 1;
|
||||
|
||||
return switch (state.flag) {
|
||||
0 => null,
|
||||
1 => .foo,
|
||||
2 => .bar,
|
||||
3 => error.Fizz,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn main() !void {
|
||||
for (0..4) |_| {
|
||||
const r1 = if (optional_enum_error_union()) |opt|
|
||||
if (opt) |val|
|
||||
switch (val) {
|
||||
.foo => "FOO",
|
||||
.bar => "BAR",
|
||||
}
|
||||
else
|
||||
"NULL"
|
||||
else |err| switch (err) {
|
||||
error.Fizz => "FIZZ",
|
||||
else => return err,
|
||||
};
|
||||
|
||||
const r2 = switch (optional_enum_error_union()) {
|
||||
.foo => "FOO",
|
||||
.bar => "BAR",
|
||||
null => "NULL",
|
||||
error.Fizz => "FIZZ",
|
||||
anyerror => |err| return err,
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user