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
KeywordIntroduces
asA conversion, value as T
breakAn exit from the nearest enclosing loop
catchA handler for the failure of a fallible expression, x 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, the default arm of a match, and the ? else mapping
enumAn enumeration of named integer values
extendAn extension block of methods, constructors and constants for a type
externA declaration of a function defined outside Rux
failA failure from a fallible function
falseThe boolean value false
forA loop over a range, slice, array or iterable
funcA function, a method or a function type
ifA conditional statement
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 primitive type, function or value
isA type test, value is T
letAn immutable binding
loopA loop with no condition
matchA selection by pattern
moduleA named module block, module A::B { … }
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
trueThe boolean value true
typeA type alias, type Name = T;
unionA union type, whose fields share storage
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 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.

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.
SelfIn 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, SomeAfter 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