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 44 words:
as break catch const continue defer do else
enum extend extern fail false finally for func
if import in interface intrinsic is let loop
match module move none null pub return self
struct throw throws true try type union unsafe
var variant when while
| Keyword | Introduces |
|---|---|
as | A conversion, value as T |
break | An exit from the nearest enclosing loop |
catch | The arms that handle an error after try, try x catch { … } or try { … } 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, statement or value |
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 or variable defined outside Rux |
fail | Nothing: it is reserved, and fail value; is rejected in favour of throw value; |
false | The boolean value false |
finally | Nothing: it is reserved, and cleanup on every exit uses defer |
for | A loop over a range, slice, array or iterable |
func | A function, a method or a function type |
if | A conditional statement, or an if value |
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 function, constant or value |
is | A type or pattern test, value is T or entry is .Some(v) |
let | An immutable binding |
loop | A loop with no condition |
match | A selection by pattern |
module | A named module block, module A::B { … } |
move | A transfer of ownership, move value, which consumes the source |
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 |
throw | A statement that throws an error, throw value; |
throws | The error a function can throw, -> T throws E |
true | The boolean value true |
try | A mark on a call that can throw: try, try?, try … catch, or a try block |
type | A type alias, type Name = T; |
union | A union type, whose fields share storage |
unsafe | An unsafe { … } block or unsafe func, where raw-pointer and foreign operations are allowed |
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 42.
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. |
thread | Directly before a module-level var: a thread-local variable, thread var Depth: int32 = 0; |
Self | In an extend block: the extended type with its type arguments, as in -> Self; in an interface: the implementing type |
_ | In a binding or pattern: discards the value instead of naming it |
Some | After a leading .: the native constructor and pattern .Some(v) of optionals, unless the expected type is a variant that declares a Some case |
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, 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