prelude
The prelude is imported into every file for you, so nothing here needs a
use. It holds the types almost every program touches: Option and Result
for values that may be missing or may have failed, Vec for growable lists,
the Range types behind a..b, and the Iterator traits that for x in
loops are built on.
Operator traits live in prelude::ops and
float math in prelude::math; both are
auto-imported too. The primitive types (int, string, …) are listed under
types.
Built into the compiler.
Modules#
| Module | Description |
|---|---|
prelude::ops | Operator traits (Add, Eq, Ord, Show, …): implement them to use operators on your types. |
prelude::math | Float math (sqrt, sin, ln, …) and small linear algebra (dot, cross, matmul, Matrix). Auto-imported. |
Types#
| Name | Description |
|---|---|
Option | An optional value: either Some(value) or None. |
Result | The outcome of an operation that can fail: Ok(value) or Err(error). |
Vec | A growable, heap-allocated vector of T values. |
Range | A lazy half-open range start..end: every value from start up to, but not including, end. |
RangeInclusive | A lazy inclusive range start..=end: every value from start up to and including end. |
Traits#
| Name | Description |
|---|---|
Iterator | A source of values that for loops pull from one at a time. |
IntoIterator | A type that can be turned into an Iterator, which makes it usable in for x in value. |