The prelude
The prelude is the part of the standard library every program gets without an import: the files at the top of runtime/. Each module after it (io, async, json, …) is brought in with an import.
- Built-in functions:
assertandpanic, which every program can call without an import. - Built-in attributes: The built-in attributes, declared as
[Attribute]structs so astaticblock can read them like its own:field.has_attribute<Deprecated>()tests for one andfunction.attribute<Deprecated>().messagereads its value (see the reflection chapter). - The reflect module (compile time):
reflectexists only inside astaticblock, which runs while compiling. - Compiler built-ins: The types and functions the compiler provides itself: raw pointers, weak references, atomics, checked arithmetic and the other
__intrinsics the runtime is built on. - Arguments and exit (deprecated): The running program’s arguments and exit, kept for the deprecated prelude
arguments()andexit(); theprocessmodule has them now. - String: A mutable, reference-counted string of UTF-8 text.
- Numbers: Reading numbers from text, and arithmetic that says what to do on overflow.
- Comparable: Ordering:
Comparable, the trait of types whose values sort in one order, which every number type,charandStringdeclare. - Ranges: Ranges of numbers:
a..banda..>b. - Array: A growable, contiguous, zero-indexed sequence of
Tvalues. - HashMap and HashSet: Hashing:
hash<T>(value), the 64-bit hashHashMapandHashSetuse for their keys, and the hash maps and sets themselves. - Map and Set: Sorted collections:
Map<K, V>andSet<K>, kept in key order on a red-black tree, andcompare<T>, the ordering they sort keys by. - OrderedMap:
OrderedMap<K, V>: a hash map that keeps its keys in the order they were first inserted. - BitSet:
BitSet: a set of small non-negative integers, stored one bit each. - Deque:
Deque: a double-ended queue over a growable ring buffer. - PriorityQueue:
PriorityQueue: a binary heap that hands out its greatest element first. - Iterators: Something a
forloop can step through, one element at a time. - Scoped: The scope protocol behind
with (var x = scope) { ... } else { ... }. - Weak: Weak references:
Weak<T>points at an object without keeping it alive. - Handle:
Handle<T>: owns a resource that Pepper’s reference counting does not know about, such as a C library’s object, and releases it when the last reference to the handle goes away, like C#’sSafeHandle. - Result:
Result<T, E>: the value of an operation that can fail, eitherOkholding its value orErrholding its error, like Rust’sResult. - Optional: A value of type
Tthat may be absent: either Value, holding aT, or Empty, holding nothing, like Rust’sOption<T>and Swift’sOptional. - Copying: Deep copies:
copy(value)makes a copy that shares no object that is not thread-safe with the original, so it can be handed to another thread;Copyable<T>lets a type say how it is copied. - URI: URI references (RFC 3986): parse any URI, such as
https://example.com/a?b#c,mailto:someone@example.comor/items?page=2, into its parts. - Test checks: Checks for tests:
expect_equal,expect_not_equal,expect_trueandexpect_false, which every program can call without an import.