Overview
The standard library is the set of modules shipped with tape. Import one by its bare name:
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
| Module | What it’s for |
|---|---|
arena | Bump allocation over memory you own, for t0 and up: over, alloc, mark, release |
io | Console output and input, streams, buffering, IoError: println, read_line, BufWriter |
fs | Files and directories: read_file, write_file, open, read_dir, mkdir_all, metadata |
bits | Bit counting, rotation, byte swapping, little- and big-endian loads and stores |
ascii | Byte classification (is_digit, is_space, …), case mapping, digit values |
bytes | Byte views without allocating: copy, fill, eq, index_of, trim, split, lines, cut |
cstr | NUL-terminated C strings at the C boundary: as_view, from_view, free |
str | Building strings: join, repeat, replace, case, padding, Builder |
fmt | Number formatting beyond "{x}": hex, binary, fixed decimals, byte sizes |
path | File paths as text: join, dirname, basename, ext, normalize |
math | Integer helpers and floating-point functions for f64 and f32: rounding, roots, trigonometry, exp/log, pow |
conv | Numbers to text and back, exactly: parse_i64, parse_f64, parse_f32, fmt_i64, fmt_f64, fmt_f32 |
mem | Heap memory and byte operations: alloc, free, copy, set, compare; live_allocs to check for leaks |
utf8 | UTF-8 text: decode, encode, validate, count, chars |
hash | Non-cryptographic hashes: fnv1a_64, wyhash, crc32, hash_i64 |
crypto | Cryptography in constant time: SHA-256/384/512, HMAC, HKDF, ChaCha20-Poly1305, AES-GCM, X25519, P-256, signature checks, a CSPRNG |
x509 | X.509 certificates for TLS: a strict DER reader, parse, host name matching, a trust store, verify_chain |
ca_roots | tape’s bundled root certificates (Mozilla’s CA set), the same on every platform: load, certs, COUNT |
tls | A 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 |
collections | Containers 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 |
sort | Sorting and binary search for slices of any type: sort_i64, sort_string, binary_search_i64, generators for your own types and orders |
rand | Seedable random numbers: xoshiro256, pcg32, range_i64, next_f64, shuffle and choice |
os | Arguments, environment, exit, working directory, platform, entropy: args, env, PLATFORM |
json | JSON: parse to a Value tree, accessors, stringify compact or indented, errors with line and column, a streaming Tokenizer |
encoding | base64, base64url, hex and percent-encoding, both ways, as strings or into your buffer |
time | Measuring and sleeping, UTC dates and ISO 8601: now, sleep, utc_now |
process | Starting programs with exact arguments, output to files, timeouts, kill, exit status: command, spawn, wait_timeout |
net | TCP and UDP sockets, name resolution, connect_host with Happy Eyeballs, poll, TCP streams as io streams, TLS connections and trust sets |
http | An HTTP/1.1 client over http and https: get, request, headers, chunked bodies, opt-in redirects, timeouts and limits, parse_url |
cli | Command lines from a declarative spec: parse, flag, value, positional, usage, message |
log | Leveled log lines with timestamps: info, warn, set_level, TAPE_LOG, sinks |
color | Building and mixing colors: rgb, channels, lighten, darken, lerp, brightness |
gfx | Drawing on a pixel surface: rectangles, shapes, text, blits, clipping, pixels and checksums |
image | PNG, JPEG, BMP and HV3 bytes to surfaces and back: decode, encode |
ui | Component trees in a window (run) or offscreen (headless): layout, painting, input, testing |
widgets | Ready-made components: Label, Button, TextInput, Checkbox, Slider, Image, … |
theme | The look of the widgets: light, dark, set at run time; the palette as #style constants |
locale | The 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.
| Pure | Capability |
|---|---|
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, theme | io, 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. Astringor a literal is accepted wherever a[]const u8is expected (see Strings as byte views). A C string goes throughcstr.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
@tapegenerators: the common ones are ready (collections.Vec_i64,collections.Map_string_i64); for others callcollections.gen_vec(Person)once and useVec_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.