Reference
Language reference
The normative text is spec/. This is the working
summary.
Declarations
| Form | Means |
|---|---|
fn name(args) -> T ! E / {row} | A function. Return, failure and effects are all part of the type. |
type N = { f: T } | A struct. |
type N = | A | B(v: T) | A sum, with or without payloads. |
type N[T] = … | A generic type: a family, one member per use. |
type N = T | An alias. |
effect N { fn op() -> T } | An effect and its operations. |
import path | Brings a module in. |
pub | Exports a declaration from its module. |
extern fn c_name(...) | A C function. Calling it performs unsafe. |
test "name" { } | A test, beside the code. |
bench "name" { } | A benchmark. |
Operators
| Operator | On |
|---|---|
+ - * / % | i64 and f64. + also concatenates a str or a list. |
^ | Exponentiation — not bitwise xor. A negative integer exponent panics; write it in floats. |
== != | Any two values of one type, structurally. |
< <= > >= | i64, f64, str, and tuples whose every component is ordered. |
and or not | Booleans. and and or short-circuit. |
?? | Opens an Option or a fallible with a default. The right side is lazy. |
|> | Pipes a value into a call. |
.. ..= | A range, exclusive or inclusive. |
Strings
Interpolation is "{expr}", and the expression inside needs no
escaping for its own quotes. len() counts characters;
byte_len() counts bytes.
Where the truth is
254 numbered clauses across spec/, each with a conformance
program that runs in the test suite. More on the
specification.