Explicit Injection
Every allocating or I/O API takes std.mem.Allocator and std.Io explicitly—no hidden globals or runtime shims.
A practical standard-library companion for Zig: native std.Io streams,
explicit allocators and I/O, and familiar high-utility packages with zero C dependencies by default.
// Go-style duration, regex & URL parsing
const std = @import("std");
const stdgo = @import("stdgo");
pub fn main(init: std.process.Init) !void {
const gpa = init.gpa;
const timeout = try stdgo.time.parseDuration("1h30m");
var re = try stdgo.regexp.compile(gpa, "https?://[^ ]+");
defer re.deinit();
const text = "Repo: https://github.com/jiacai2050/stdgo";
const matched = re.findString(text) orelse return error.NotFound;
const u = try stdgo.net.url.parse(matched);
std.debug.print("{s}{s} ({d}s)\n", .{ u.host, u.path, timeout.seconds() });
}
// Structured logging (log.slog) to any std.Io.Writer
const std = @import("std");
const stdgo = @import("stdgo");
pub fn main(init: std.process.Init) !void {
var log_buf = stdgo.bytes.Buffer.init(init.gpa);
defer log_buf.deinit();
var handler = stdgo.log.slog.TextHandler.init(log_buf.writer(), .info);
var logger = stdgo.log.slog.Logger.init(handler.handler(), init.io);
try logger.info("parsed repo", &.{
.string("host", "github.com"),
.string("path", "/jiacai2050/stdgo"),
.int("timeout_s", 5400),
});
std.debug.print("{s}", .{log_buf.string()});
}
// Bounded structured concurrency (sync.ErrGroup)
const std = @import("std");
const stdgo = @import("stdgo");
pub fn main(init: std.process.Init) !void {
const Worker = struct {
fn run(task_io: std.Io, id: usize) !void {
try task_io.checkCancel();
std.debug.print("worker {d} done\n", .{id});
}
};
const Args = std.meta.ArgsTuple(@TypeOf(Worker.run));
const tasks = [_]Args{ .{ init.io, 1 }, .{ init.io, 2 }, .{ init.io, 3 } };
try stdgo.sync.ErrGroup.run(init.gpa, init.io, Worker.run, &tasks, 2);
}
API Reference
Generated directly with zig build docs from the source tree.
Architecture
Go developer experience without sacrificing Zig's explicit control.
Every allocating or I/O API takes std.mem.Allocator and std.Io explicitly—no hidden globals or runtime shims.
stdgo.io.Reader and Writer alias std.Io directly for zero-copy streaming across HTTP, compression, and archives.
Cooperative cancellation via std.Io.Future, CancelSource, and explicit Deadline values instead of opaque contexts.
Pure Zig implementations across the core suite, with optional -Dsqlite=true when you want the SQLite driver.
Package Ecosystem
30+ top-level packages verified with comprehensive unit tests.