Keywords
A keyword is a word the language reserves. Keywords are lower case and case-sensitive, and none of them can be used as an identifier: While is an ordinary name, while is not.
Reserved keywords
Rux reserves 38 words:
as break catch const continue defer do else
enum extend extern fail false for func if
import in interface intrinsic is let loop match
module none null pub return self struct true
type union var variant when while
| Keyword | Introduces |
|---|---|
as | A conversion, value as T |
break | An exit from the nearest enclosing loop |
catch | A handler for the failure of a fallible expression, x catch { … } |
const | A compile-time constant |
continue | A jump to the next iteration of a loop |
defer | A statement run when the enclosing scope exits |
do | A do { … } while condition; loop, which tests after the body |
else | The alternative of an if, the default arm of a match, and the ? else mapping |
enum | An enumeration of named integer values |
extend | An extension block of methods, constructors and constants for a type |
extern | A declaration of a function defined outside Rux |
fail | A failure from a fallible function |
false | The boolean value false |
for | A loop over a range, slice, array or iterable |
func | A function, a method or a function type |
if | A conditional statement |
import | Names brought into scope from a package or module |
in | The sequence of a for loop, for item in items |
interface | A set of methods a type can implement |
intrinsic | A declaration the compiler implements: a primitive type, function or value |
is | A type test, value is T |
let | An immutable binding |
loop | A loop with no condition |
match | A selection by pattern |
module | A named module block, module A::B { … } |
none | The absent value of an optional |
null | The null pointer |
pub | Visibility outside the declaring package |
return | A return from the enclosing function |
self | The receiver parameter of a method |
struct | A structure type |
true | The boolean value true |
type | A type alias, type Name = T; |
union | A union type, whose fields share storage |
var | A mutable binding, and writability in &var T, *var T and var T[..] |
variant | A tagged type whose cases may carry payloads |
when | A compile-time conditional |
while | A loop that tests a condition before each iteration |
true and false are lexed as boolean literals, and are reserved like the other 36.
Contextual words
These words are ordinary identifiers except in one position, where they take a fixed meaning. Outside that position they can name things, although using them as names makes code harder to read.
| Word | Meaning, and where |
|---|---|
asm | Directly before func: a function whose body is assembly |
sizeof, alignof | In an expression: the size or alignment of a type, sizeof(T). An expression cannot read a binding with either name. |
Self | In an interface or extension: the implementing type, as in other: &Self |
_ | In a binding or pattern: discards the value instead of naming it |
Success, Failure, Some | After a leading .: the native constructors and patterns .Success(v), .Failure(e) and .Some(v) of fallibles and optionals |
Primitive type names — int, uint8, float64, bool, char and the rest — are not keywords either. They are predefined type names, listed in the Primitive Types appendix, and so is opaque, the unknown pointee of an untyped pointer *opaque.
Some words that other languages reserve mean nothing special in Rux: mut, try, unsafe, use, impl and fn are ordinary identifiers.
See also
- Identifiers — what a name may be
- Token Reference — every token, keywords included
- Cheat sheet — the whole language on one page