From 7cf8a796876753df6e1ea077bd06ece8ea819c8f Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 23 Aug 2026 15:34:28 -0500 Subject: [PATCH] use the Init parameter of main in the enumerate example Zig 0.16 lets main take a std.process.Init, in which case the runtime builds the allocator and the Io implementation and passes them in. That removes ten lines of DebugAllocator and Io.Threaded scaffolding from the example, along with the chance of getting its teardown order wrong. The prose above the example claimed the examples use Io.Threaded, which is no longer true, so it now explains init.io as the easy way to obtain an Io and notes that constructing one by hand is what a library caller needs. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01SbEyBWpAnyGNMQTNWADqDB --- README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ad5851c..b8c5057 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,12 @@ exe.root_module.addImport("hidapi", hidapi.module("hidapi")); ## Usage -Every call takes a `std.Io` as its first argument. The examples below use -`std.Io.Threaded`, but any implementation (such as `std.Io.Uring`) will do. +Every call takes a `std.Io` as its first argument. Declaring `main` with a +`std.process.Init` parameter is the easiest way to get one: the runtime builds +an `Io` implementation appropriate for the target and hands it over as +`init.io`. Constructing one yourself (`std.Io.Threaded`, `std.Io.Uring`) works +just as well, and is what you need when the caller is a library rather than +`main`. ### Enumerating devices @@ -53,13 +57,8 @@ Every call takes a `std.Io` as its first argument. The examples below use const std = @import("std"); const hidapi = @import("hidapi"); -pub fn main() !void { - var debug_allocator: std.heap.DebugAllocator(.{}) = .init; - defer _ = debug_allocator.deinit(); - - var threaded: std.Io.Threaded = .init(debug_allocator.allocator(), .{}); - defer threaded.deinit(); - const io = threaded.io(); +pub fn main(init: std.process.Init) !void { + const io = init.io; var buf: [256]u8 = undefined; var it: hidapi.DeviceInfoIterator = .init; -- knotmirror 0.0.1