rokdocs
v0.1

rok standard library reference

This is the formal specification of the rok standard libraries. Where the language specification defines syntax and semantic mechanisms, the standard library specification supplies the meaning of the types, traits and functions those mechanisms need in order to actually work. It defines in one place which traits operators resolve to, which interfaces collections have, and on which guarantees async and I/O operate.

The language specification is collected separately in refs-lang/; this document covers only the specification. The actual implementation of the libraries is outside the scope of the spec.

Important

Boundary between the language specification and the standard library specification

refs-lang defines syntax and semantic mechanisms (e.g. which trait method the + token maps to). refs-standard-libraries (this document) defines the signatures and meaning of those traits themselves (e.g. which numeric conversion Add::add applies).

Both specifications follow the same notation conventions.


The 3-tier model

The standard libraries are not a single flat plane but are divided into three layers. Almost all systems code is written on top of safe abstractions, but implementing those abstractions eventually requires handling raw memory and FFI somewhere. Moreover, features that are meaningful only with a host environment, such as files or networking, must not exist at all on targets without such an environment, such as embedded. To expose these differences directly in the dependency graph, the libraries follow a 3-tier structure under the virtual namespace rok::: rok::bare / rok::core / rok::std.

rok::bare   (base, depends only on runtime extern "C")
  ↓
rok::core   (foundation, safe, all targets - uses rok::bare internally)
  ↓
rok::std   (target-dep - uses rok::core + rok::bare)

rok::bare exposes only raw capabilities at the bottom, and rok::core provides a safe foundation on top of it, identically on every target. rok::std adds host-dependent features on top of rok::core, completing the surface an ordinary application expects. Everyday code needs only rok::core; it reaches for rok::std the moment OS resources are needed, and imports rok::bare explicitly only when it must cross an abstraction boundary directly. The detailed dependency rules are covered in 0.1 Tier model.

TierPathDirectoryArea
rok::barerok::bare::*100-bare/Ptr, ConstPtr, transmute, raw alloc, pin
rok::corerok::core::*200-core/Numbers, operators, iter, collections, fmt, sync, task
rok::stdrok::std::*300-std/fs, net, time, thread, io, env, process, path, crypto (random)

Chapters

0. Meta - 000-meta/

Library-wide policies and tables.

1. Unsafe - 100-bare/

Low-level / dangerous area. Explicit import required.

2. Rok - 200-core/

Safe area. All targets. use rok::core::**; applied implicitly (no separate prelude module).

Note

Scientific computing / AI areas such as tensors / automatic differentiation / SIMD / GPU are not part of the standard libraries and are split out into external libraries. External libraries can access MLIR dialects directly through the rok::bare::mlir module.

3. Std - 300-std/

Target-dependent area. Explicit import.


How to read

First reading

On a first approach, it is recommended to follow Chapters 0-6 of refs-lang to understand the language's mechanisms, and then read this document on top of that. This document gives meaning to the mechanisms refs-lang defines; without a feel for those mechanisms, the traits and signatures tend to read as if floating in the air. Reading the two documents side by side, moving back and forth, is the most efficient approach.

As a reference

Each item is identified by a stable section number (<chapter>.<section>). The number is used identically in internal links and external references, so it points reliably even if files move.

refs-standard-libraries 2.3        →  rok ops (Add/Sub/...)
refs-standard-libraries 1.1        →  unsafe Ptr<T>
refs-standard-libraries 3.5.2      →  std io (specific subsection)

To find a specific trait or function quickly, the lightest approach is to search with ripgrep, narrowing the directory.

rg "trait Add" spec/en/refs-standard-libraries/200-core/
rg "fn into" spec/en/refs-standard-libraries/

Directory / file naming

This document follows a different directory convention from refs-lang, because the two specifications have different shapes: refs-lang is a flat structure in which chapters 0 through 9 all have equal authority, whereas refs-standard-libraries is a hierarchical structure in which the three tiers act as the key information in cross-references. This structural difference is reflected directly in the number of digits in directory names.

SpecificationPrefixReason
refs-langOne digit (002-)10 chapters (0-9), all with equal authority - flat shape
refs-standard-librariesThree digits (200-)3 tiers × N modules - the tier is key cross-reference information

The concrete file naming rules are as follows. Tier directories have prefixes in units of 100, and module files within them start with a three-digit prefix combining one tier digit and two module digits.

LocationFormExample
Tier<TNN>-<descriptive-name>/100-bare/, 200-core/
Module<tier><module>-<name>.md203-ops.md, 211-conversion.md
(one tier digit + two module digits)
READMEREADME.md in each tier / chapterTOC + overview

Although tier information is encoded in the file path itself, the stable section number (2.3.1, etc.) is the formal notation when citing this document externally. File paths serve only as an auxiliary notation for navigation convenience in IDEs and GitHub.

Edit this page on GitHub