I need to check that a clock is available before I use it:
pub fn run(parsed: cli.Parsed(command)) !void {
var gpa = std.heap.DebugAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
var io_impl = std.Io.Threaded.init_single_threaded;
const io = io_impl.io();
const clock = std.Io.Clock.boot;
const resolution = clock.resolution(io) catch |err| switch (err) {
error.ClockUnavailable => {
std.log.err(".boot clock unavailable but is required", .{});
return error.NonRecoverable;
},
error.Unexpected => {
std.log.err("unexpected error when querying clock resolution", .{});
return error.NonRecoverable;
},
};
std.log.warn("clock({s}) resolution: {} ns", .{ @tagName(clock), resolution.toNanoseconds() });
_ = clock.resolution(io) catch unreachable;
_ = clock.now(io);
// clock must work beyond this point.
....
}
How can I document my requirement that the clock must be available (via non-error return of clock.resolution) with assert? catch unreachable does say this but I would prefer to use assert if possible to be extra explicit.
I’m hesitant to use an equality comparison because tigerbeetle bans them: tigerbeetle/src/tidy.zig at 6b5a2e9016a02587e929699d84a0ab585b2b46c8 · tigerbeetle/tigerbeetle · GitHub
Secondary question: why does tigerbeetle ban them? What is silent anyerror upcast?