vector drawing of a book with zig logo

The Zig Standard Library

This page contains a human-curated directory for the Zig standard library. All *.zig links point to HTML documents which have been automatically generated from the library source.

The files are split into two columns: The right column is the raw Zig source code in the file. The left column will contain public identifiers and any document comments to explain them.

Data structures

array_list.zig Probably the most commonly used data structure in Zig. This is a resizeable list. Contains a huge number of handy methods for manipulating a list. See Standard Patterns: ArrayList (ziglearn.org).

bounded_array.zig For fixed-size lists. Compare with ArrayList.

multi_array_list.zig A list of structs, but stores the fields of the structs efficiently as contiguous lists. See Struct of Arrays (SoA) in Zig? Easy & in Userland! (zig.news).

array_hash_map.zig A "hash" or "dictionary" storing values by hashed key. For typical needs, consider StringHashMap or AutoHashMap. See Zig hashmaps explained (hexops.com).
buf_map.zig A StringHashMap that copies and frees keys and values for you!
buf_set.zig A StringHashMap that works as a set of strings.
comptime_string_map.zig Basically a StringHashMap that hashes at comptime!

enums.zig Functions for working with Zig's enums.

fifo.zig and priority_dequeue.zig and priority_queue.zig General-purpose queue structures with handy methods.

BitStack.zig An ArrayList of bits with stack methods like push() and pop(). See

RingBuffer.zig A circular buffer with a backing slice with read/write and slicing operations.

linked_list.zig Contains SinglyLinkedList() and DoublyLinkedList() linked list types.

treap.zig A treap (wikipedia.org) binary search tree.

packed_int_array.zig Read and write integers packed into memory like sardines.

bit_set.zig Bit sets let you manipulate the individual bits of your bytes. This file contains multiple bit set types and has good descriptions of each.

See also: atomic.zig under Parallel and concurrent execution.

Zig-specific

std.zig The starting point for the whole standard library. This is what gets included when you do const std = @import("std");. Imports the rest of the namespace. You can start here to browse most of the library in this HTML version.

zig.zig Zig code tokenzing, parsing, abstract syntax tree, etc. Zig in Zig so you can Zig while you Zig.

meta.zig Comptime introspection for Zig data types. (Get the fields from a struct, for example).

testing.zig A bunch of helpful functions (and even an allocator that fails on purpose) for your test blocks.

debug.zig Contains helpful functions such as std.debug.print(), assert(), panic(), and dumpCurrentStackTrace().

Build.zig Zig's build API provides functionality to perform just about any compilation or file manipulation tasks you might need to build a project. (You typically call its features from a build.zig file.)

builtin.zig All sorts of meta Zig stuff. Contains types returned by the builtin functions (@foo()).

Memory and allocation

mem.zig Contains lots of functions for manipulating memory such as sort(), eql(), indexOfDiff(), sliceTo(), len(), trim(), indexOf(), indexOfAny(), indexOfNone(), readIntNative(), writeIntNative(), tokenizeSequence(), splitSequence(), SplitIterator(), alignInSlice(), and many more.

mem/Allocator.zig Contains the interface used by all memory allocation features in the Zig standard library.

heap.zig Defines many allocation strategies for managing memory including heap/general_purpose_allocator.zig, heap/PageAllocator.zig, heap/arena_allocator.zig, and heap/memory_pool.zig.

See

General utilities

fmt.zig String formatting (this is how print() works), number parsing, etc. TODO: I need to make a "zig fmt by example" page.

io.zig Input/Output support for reading and writing data. Includes io/Reader.zig, io/writer.zig, io/bit_reader.zig, io/bit_writer.zig, io/buffered_reader.zig, io/buffered_writer.zig, and io/tty.zig.

log.zig Standardized logging with support for levels (err, warn, info, debug).

Progress.zig Terminal progress indicator (uses ANSI escape sequences when possible).

sort.zig Sorting and searching algorithms such as insertion(), heap(), binarySearch(), min(), and max().

json.zig Read and write data to and from the JSON serialization format.

Ini.zig Read INI (*.ini) formatted configuration files.

tar.zig Support for the Tar (wikipedia.org) archive file format.

crypto.zig A huge number of cryptographic functions.
Hashes: crypto/md5.zig, crypto/sha1.zig, crypto/sha2.zig, crypto/sha3.zig, crypto/bcrypt.zig, crypto/scrypt.zig, and more.
Cryptography: crypto/25519/curve25519.zig, crypto/25519/ed25519.zig, crypto/aes.zig, and more.
See also: crypto/tls.zig and crypto/Certificate.zig under Networking.

hash.zig More general hashing algorithms.

rand.zig Fast and/or cryptographically secure pseudo-random number generators.

leb128.zig Read and write LEB128 (wikipedia.org) Little Endian Base 128 numbers.

SemanticVersion.zig Read (parse), write, and sort semantic version numbers.

unicode.zig Functions for handling encoded Unicode sequences: utf8Encode(), utf8Decode(), utf8ValidateSlice(), utf16leToUtf8Alloc(), etc.

ascii.zig Handy functions for testing u8 values as 7-bit ASCII characters (isAlphabetic(), toUpper(), etc.

base64.zig Encode and decode Base64 (wikipedia.org) data.

c.zig Utilities for interoperating with C code. Also contains a lot of OS and architecture-specific function implementations. (See a partial list under OS.)

time/epoch.zig Important dates for common OSs and some simple date calculations.

tz.zig Handle Earth timezone files.

compress.zig Contains a large number of compression/decompression algorithms such as compress/gzip.zig, compress/xz.zig, compress/zlib.zig, and more!

math.zig General mathematical operations.

simd.zig Functions for working with SIMD (Single Instruction; Multiple Data), if hardware support is present.

valgrind.zig Support for working with the Valgrind memory leak detection and profiling tool.

OS and architecture-specific

os.zig Wrappers for a very large list of OS-specific functions. Includes Unix-like, Emscripten, WASI, Plan9, UEFI, and Windows.

target.zig Functionality for building Zig programs for a big list of processor architectures.

process.zig Environment information, etc. for processes (e.g. current working directory and environment variables).

time.zig Get time, measure time, and sleep.

start.zig The start() function for executable files. Handles OS-specific startup tasks.

elf.zig Support for the ELF (wikipedia.org) executable format.

coff.zig Support for the COFF (wikipedia.org) executable format.

macho.zig Support for the Mach-O (wikipedia.org) executable format.

dwarf.zig Support for the DWARF (wikipedia.org) debugging data format.

pdb.zig Support for the PDB (wikipedia.org) debugging data format.

wasm.zig WASM opcode list and functions.

Thread.zig Native operating system thread support.

child_process.zig Native child process spawning support.

dynamic_library.zig Utilities for working with dynamic libraries (.dll, .so, etc.)

fs.zig File system support. Contains fs/file.zig, fs/path.zig, fs/wasi.zig, and fs/watch.zig.

See also: the C-code files such as c/linux.zig, c/openbsd.zig, c/freebsd.zig, c/netbsd.zig, c/darwin.zig, c/wasi.zig, c/windows.zig, etc.

Parallel and concurrent execution

atomic.zig Support for atomic access to shared memory. See specific data structures in atomic/queue.zig and atomic/stack.zig.

once.zig Executes a function just once.

event.zig Support for various types of event-based programming.
Examples: event/batch.zig, event/future.zig, and event/loop.zig.

See also: Thread.zig and child_process.zig under OS.

Networking

net.zig Networking functions for TCP/IP, Unix Sockets, DNS, etc.

Uri.zig
Read and write (parse) URIs (see the tests in this one!).

crypto/tls.zig and crypto/Certificate.zig for cryptographic networking.

http.zig HTTP support! Includes http/Client.zig, http/Headers.zig, and http/Server.zig.