Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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: assert and panic, which every program can call without an import.
  • Built-in attributes: The built-in attributes, declared as [Attribute] structs so a static block can read them like its own: field.has_attribute<Deprecated>() tests for one and function.attribute<Deprecated>().message reads its value (see the reflection chapter).
  • The reflect module (compile time): reflect exists only inside a static block, 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() and exit(); the process module 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, char and String declare.
  • Ranges: Ranges of numbers: a..b and a..>b.
  • Array: A growable, contiguous, zero-indexed sequence of T values.
  • HashMap and HashSet: Hashing: hash<T>(value), the 64-bit hash HashMap and HashSet use for their keys, and the hash maps and sets themselves.
  • Map and Set: Sorted collections: Map<K, V> and Set<K>, kept in key order on a red-black tree, and compare<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 for loop 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#’s SafeHandle.
  • Result: Result<T, E>: the value of an operation that can fail, either Ok holding its value or Err holding its error, like Rust’s Result.
  • Optional: A value of type T that may be absent: either Value, holding a T, or Empty, holding nothing, like Rust’s Option<T> and Swift’s Optional.
  • 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.com or /items?page=2, into its parts.
  • Test checks: Checks for tests: expect_equal, expect_not_equal, expect_true and expect_false, which every program can call without an import.