Extensions to the Zig 0.16 and 0.17 standard libraries: fixed-capacity containers, strict parsers, IPv4 types, and the primitives std lacks.
The same helpers kept showing up copy-pasted across projects: strict number parsing, IPv4 and CIDR handling, fixed-capacity buffers, a bounded writer, a slab allocator. stdx is where they live. Each module is tested on its own, and the library imports only std.
- Modules: every export of
src/root.zig, one row each, with the reason to reach for it. - Choosing a container: which fixed-capacity type fits a need, and when to use std or
swissinstead. - Fixed-capacity containers: lists, queues, bitsets, maps, sets, Bloom filters, and comptime lookup tables. No allocator and no
deinit;Arrayowns its storage, andSliceandQueueborrow it. - Ordered maps:
btree.Autoandbtree.Stringkeep the keys sorted for iteration and lookups by key. - Strict parsing:
fmt.atoiaccepts one grammar for machine-written integers and rejects the rest.fmt.parseBoolaccepts Go's boolean spellings. - Configuration files:
dotenv.parsereads a.envfile against one documented grammar, returns borrowed slices, and reports the line that does not fit. - JSON with comments:
jsonc.parseFromSlicereads a config file with//and/* */comments and trailing commas, and keeps every byte offset sostd.jsonerrors point at the right line and column in the source. - String dispatch:
enums.Openandenums.Closedturn a byte-string list into an enum for aswitch.stringToEnummatches an existing enum with fixed-length compares. - Prefix matching:
prefix_map.Mapis a compressed radix tree over byte strings. It builds at comptime or runtime and returns the longest stored prefix. - Initialize once:
once.Cellandonce.Lazyset a value at most once. TheSyncvariants share it across threads with a lock-free read. - Sort:
sort.radixis a stable integer radix sort.sort.nthandsort.selectfind the k-th element without sorting the rest. - Cache the recent:
lru.Stringandlru.Autokeep a fixed number of entries.getmoves a hit to the front;putevicts the tail. - Binary encoding:
wire.Writerwrites integers, enums, and slices into caller-owned bytes, in big or little endian selected at comptime, with a reserved slot for a length or checksum written later. - Base32: a Crockford base32 codec for fixed-shape machine tokens. The decode itself is the validation, and every spelling outside the lowercase alphabet fails.
- IP addresses:
net.Ip4andnet.Prefix4, following Go'snet/netip: classification, ordering, canonical prefixes, and overlap checks.HostPortsplitshost:portconfig text. - UUIDs:
Uuidgenerates version 4 and version 7 values, formats them, and parses the canonical text form. - Timekeeping: clock reads with no
Iovalue, a per-tick cached clock, wall time for log lines, RFC 3339 formatting, and a log rate limiter. - Timers: a caller-driven set of deadlines over
Io.Timestamp, with callbacks, removal by handle, and period re-arm without drift. - Logging transport:
slot_ring.Mpscmoves log lines from worker threads to one consumer. Producers never block, and a refused claim drops the new message. - Small modules: a bounded writer, rapidhash, the heap pools and bump arena, fixed-size byte values, secure random, and buffered stdio.
zig fetch --save https://baskingspot.dev/stdx/v0.3.0.tar.gzAdd the module to your build:
const stdx = b.dependency("stdx", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("stdx", stdx.module("stdx"));stdx builds with Zig 0.16 and 0.17.
- The guide says which piece to use for a task, with examples that compile.
- The API reference documents every symbol.
just cinix develop provides the toolchain and the site tools. just lists the recipes, and just ci runs what CI runs. just guide serves the guide with live reload, and just doc builds the whole site into zig-out/site/stdx/.
MIT. See LICENSE. Parts are adapted from other code; THIRD_PARTY.md says which, and under what terms. The logo files in docs/static/ are baskingspot marks and are not covered by it. See docs/static/LICENSE.
Built with LLM assistance. How, in detail.