v0.4.0

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
KeywordIntroduces
asA conversion, value as T
breakAn exit from the nearest enclosing loop
catchThe arms that handle an error after try, try x catch { … } or try { … } catch { … }
constA compile-time constant
continueA jump to the next iteration of a loop
deferA statement run when the enclosing scope exits
doA do { … } while condition; loop, which tests after the body
elseThe alternative of an if, statement or value
enumAn enumeration of named integer values
extendAn extension block of methods, constructors and constants for a type
externA declaration of a function or variable defined outside Rux
failNothing: it is reserved, and fail value; is rejected in favour of throw value;
falseThe boolean value false
finallyNothing: it is reserved, and cleanup on every exit uses defer
forA loop over a range, slice, array or iterable
funcA function, a method or a function type
ifA conditional statement, or an if value
importNames brought into scope from a package or module
inThe sequence of a for loop, for item in items
interfaceA set of methods a type can implement
intrinsicA declaration the compiler implements: a function, constant or value
isA type or pattern test, value is T or entry is .Some(v)
letAn immutable binding
loopA loop with no condition
matchA selection by pattern
moduleA named module block, module A::B { … }
moveA transfer of ownership, move value, which consumes the source
noneThe absent value of an optional
nullThe null pointer
pubVisibility outside the declaring package
returnA return from the enclosing function
selfThe receiver parameter of a method
structA structure type
throwA statement that throws an error, throw value;
throwsThe error a function can throw, -> T throws E
trueThe boolean value true
tryA mark on a call that can throw: try, try?, try … catch, or a try block
typeA type alias, type Name = T;
unionA union type, whose fields share storage
unsafeAn unsafe { … } block or unsafe func, where raw-pointer and foreign operations are allowed
varA mutable binding, and writability in &var T, *var T and var T[..]
variantA tagged type whose cases may carry payloads
whenA compile-time conditional
whileA 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.

WordMeaning, and where
asmDirectly before func: a function whose body is assembly
sizeof, alignofIn an expression: the size or alignment of a type, sizeof(T). An expression cannot read a binding with either name.
threadDirectly before a module-level var: a thread-local variable, thread var Depth: int32 = 0;
SelfIn 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
SomeAfter 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