Standard Library Overview

Toka's standard library provides a comprehensive set of modules for everyday programming tasks.

Module Structure

The standard library is organized into four tiers:

lib/core/ — Core Language Primitives

These modules provide the fundamental types and traits that the language itself depends on:

ModuleDescription
preludeAuto-imported basics for every Toka program
typesType definitions and limits
traitsCore traits (@Hash, @PartialEq, @PartialOrd)
charUnicode character handling and classification
strString slice operations
stringUTF-8 dynamic string type and views
bytesRead-only binary byte-stream view
memoryMemory management primitives
optionOption<T> type for nullable values
resultResult<T, E> type for error handling
taskFundamental coroutine execution runtime and task base

lib/sys/ — Low-level System Primitives

These modules provide direct bindings and primitives interacting with the operating system and low-level runtime:

ModuleDescription
libcPlatform-dependent C standard library API declarations and bindings
termiosLow-level Tty terminal mode and control attributes configuration
threadLower-level OS native thread interfaces
syncOS-level synchronization primitives and lock implementations
linux / macos / windowsPlatform-specific system calls and bindings

lib/std/ — Standard Library

Ready-to-use standard modules for application development:

ModuleDescription
vecDynamically growing sequential array container (Vec)
dequeDouble-ended queue based on ring buffers (VecDeque)
slabZero-copy generational slab allocator (Slab / SlabID)
hashmapHigh-performance hash table based map (HashMap)
hashsetHash table based unique element collection (HashSet)
btreemapB-Tree based ordered key-value map (BTreeMap)
btreesetB-Tree based ordered unique set (BTreeSet)
heapPriority queue implemented with max/min binary heap (BinaryHeap)
arenaRegion-based arena allocator for high performance allocation (Arena)
ringHigh throughput lock-free ring buffers (RingBuffer)
ioBuffered standard console I/O (stdin / stdout / println)
fsFile system read/write and directory metadata operations
pathCross-platform file path parsing and manipulation (Path / PathBuf)
envEnvironment variables, process arguments, and system context interaction
processSubprocess spawning, state control, and pipe communication
threadOS native thread management and lifecycle control (Thread)
syncThread synchronization primitives (Mutex / Condvar / WaitGroup)
atomicHardware-level atomic operations and lock-free sync primitives
channelThread message passing communication channel (channel / sync_channel)
taskCoroutine task scheduling, context management, and async runtime
netTCP & UDP socket network communication interfaces
mathCommon mathematical functions and limit constants
timeSystem time and monotonic durations (Duration / Instant)
fmtText formatting and debug printing utilities (Format)
errorCommon error traits (Error) and failure base definitions
panicRuntime fatal error triggering, intercepting, and stack hooks

lib/stdx/ — Experimental / Extended (stdx)

New modules that are still evolving or optional extensions:

ModuleDescription
logBasic logging utilities and severity filtering
net/httpHTTP client and server
net/urlURL parsing
net/websocketWebSocket client and server
serde/jsonJSON serialization
crypto/md5MD5 hashing
crypto/sha1SHA-1 hashing
crypto/sha256SHA-256 hashing
encoding/base64Base64 encoding and decoding
encoding/hexHexadecimal encoding and decoding
io/bufioBuffered advanced I/O streams (BufReader / BufWriter)
rand/randPseudo-random number generator and random utilities (Random)
trace/spanMethod execution timing and trace spans
cli/flagCLI flag parsing

Design Philosophy

Toka's standard library follows these principles:

  1. Zero dependencies — Everything is built with pure Toka and the LLVM backend
  2. Consistent API — Similar patterns across different modules
  3. Error-aware — Every fallible operation returns Result or Option
  4. Performant — Compiled to native code with no hidden overhead