Overview

The standard library is the set of modules shipped with tape. Import one by its bare name:

tape
import io from "io";
import collections from "collections";

tape finds them in stdlib/ next to the tape binary (or in ./stdlib, or any -I path). They’re ordinary tape modules: you can read their source.

Modules

ModuleWhat it’s for
arenaBump allocation over memory you own, for t0 and up: over, alloc, mark, release
ioConsole output and input, streams, buffering, IoError: println, read_line, BufWriter
fsFiles and directories: read_file, write_file, open, read_dir, mkdir_all, metadata
bitsBit counting, rotation, byte swapping, little- and big-endian loads and stores
asciiByte classification (is_digit, is_space, …), case mapping, digit values
bytesByte views without allocating: copy, fill, eq, index_of, trim, split, lines, cut
cstrNUL-terminated C strings at the C boundary: as_view, from_view, free
strBuilding strings: join, repeat, replace, case, padding, Builder
fmtNumber formatting beyond "{x}": hex, binary, fixed decimals, byte sizes
pathFile paths as text: join, dirname, basename, ext, normalize
mathInteger helpers and floating-point functions for f64 and f32: rounding, roots, trigonometry, exp/log, pow
convNumbers to text and back, exactly: parse_i64, parse_f64, parse_f32, fmt_i64, fmt_f64, fmt_f32
memHeap memory and byte operations: alloc, free, copy, set, compare; live_allocs to check for leaks
utf8UTF-8 text: decode, encode, validate, count, chars
hashNon-cryptographic hashes: fnv1a_64, wyhash, crc32, hash_i64
cryptoCryptography in constant time: SHA-256/384/512, HMAC, HKDF, ChaCha20-Poly1305, AES-GCM, X25519, P-256, signature checks, a CSPRNG
x509X.509 certificates for TLS: a strict DER reader, parse, host name matching, a trust store, verify_chain
ca_rootstape’s bundled root certificates (Mozilla’s CA set), the same on every platform: load, certs, COUNT
tlsA TLS 1.3 client as a sans-I/O engine: you move the bytes, it does the protocol; certificate checks through x509, ALPN, KeyUpdate, leaf pinning
collectionsContainers for any element type: Vec, Map and Set (integer, string or custom keys), Deque, Heap, BitSet; Vec_i64, Map_string_i64 and others ready to use
sortSorting and binary search for slices of any type: sort_i64, sort_string, binary_search_i64, generators for your own types and orders
randSeedable random numbers: xoshiro256, pcg32, range_i64, next_f64, shuffle and choice
osArguments, environment, exit, working directory, platform, entropy: args, env, PLATFORM
jsonJSON: parse to a Value tree, accessors, stringify compact or indented, errors with line and column, a streaming Tokenizer
encodingbase64, base64url, hex and percent-encoding, both ways, as strings or into your buffer
timeMeasuring and sleeping, UTC dates and ISO 8601: now, sleep, utc_now
processStarting programs with exact arguments, output to files, timeouts, kill, exit status: command, spawn, wait_timeout
netTCP and UDP sockets, name resolution, connect_host with Happy Eyeballs, poll, TCP streams as io streams, TLS connections and trust sets
httpAn HTTP/1.1 client over http and https: get, request, headers, chunked bodies, opt-in redirects, timeouts and limits, parse_url
cliCommand lines from a declarative spec: parse, flag, value, positional, usage, message
logLeveled log lines with timestamps: info, warn, set_level, TAPE_LOG, sinks
colorBuilding and mixing colors: rgb, channels, lighten, darken, lerp, brightness
gfxDrawing on a pixel surface: rectangles, shapes, text, blits, clipping, pixels and checksums
imagePNG, JPEG, BMP and HV3 bytes to surfaces and back: decode, encode
uiComponent trees in a window (run) or offscreen (headless): layout, painting, input, testing
widgetsReady-made components: Label, Button, TextInput, Checkbox, Slider, Image, …
themeThe look of the widgets: light, dark, set at run time; the palette as #style constants
localeThe active locale for @t strings: set, get, from LANG/LC_ALL, available

Pure and capability modules

A pure module only computes: it has no effect besides its return values and the memory you hand it (allocating memory is allowed). A capability module touches the outside world: the console, the clock, files, processes, the network, windows.

PureCapability
bits, ascii, cstr, str, fmt, path, mem, math, collections, sort, rand, color, arena, utf8, hash, crypto, x509, ca_roots, tls, conv, bytes, cli, json, encoding, gfx, image, themeio, fs, os, time, process, net, http, log, ui, widgets, locale

A pure module never imports a capability module, so code that uses only pure modules can’t do I/O. A host that embeds tape can rely on that.

Conventions

  • Text is passed as []const u8. A string or a literal is accepted wherever a []const u8 is expected (see Strings as byte views). A C string goes through cstr.as_view(p) first.
  • Errors are enum values returned as T or SomeError, each with a description, so "{err}" reads well.
  • Generated containers come from @tape generators: the common ones are ready (collections.Vec_i64, collections.Map_string_i64); for others call collections.gen_vec(Person) once and use Vec_Person. You don’t import the modules the generated code uses. A container owns copies of its elements and is itself a managed value: it is freed when its variable goes out of scope and copied by assignment (see collections and Ownership).

Testing

Modules carry their tests in a #test region. tape test stdlib/cstr.tape runs them in the VM and as native code and checks that both agree; see tape test.