Keywords and Reserved Words
Keywords are reserved words that have special meaning in the language.
Keywords
The following words are keywords and cannot be used as identifiers:
| Keyword | Description |
|---|---|
borrow | Borrow parameter mode |
fn | Function declaration |
inout | Inout parameter mode |
let | Variable binding |
linear | Linear struct modifier |
mut | Mutable binding modifier |
if | Conditional expression |
else | Alternative branch |
while | While loop expression |
loop | Infinite loop expression |
for | For loop expression |
in | Iterable separator in a for loop |
match | Pattern matching expression |
return | Return from function |
break | Exit loop |
comptime | Compile-time evaluation |
continue | Skip to next iteration |
true | Boolean literal |
false | Boolean literal |
struct | Struct definition |
enum | Enum definition |
impl | Reserved syntax; Rue has no impl-block construct (6.0:1a) |
interface | Interface declaration (6.8, --preview interfaces) |
self | Self parameter in methods |
drop | Destructor declaration |
pub | Public visibility modifier |
const | Constant declaration |
checked | Checked block (§9.1) |
unchecked | Unchecked function modifier |
ptr | Pointer type constructor (ptr const T / ptr mut T) |
extern | Foreign declaration block (extern "C" { … }, ADR-0064) |
yield | Accessor body exit (-> borrow T/-> inout T accessors, ADR-0062) |
Contextual Keywords
A contextual keyword is an identifier that has special meaning only in a grammatical position that expects it and is an ordinary identifier everywhere else. is is a contextual keyword: it introduces a conformance list after a struct name or after the subject type of a freestanding conformance assertion (6.8:2), and it remains usable as the name of a binding, parameter, field, function, or method.
Type Names
The following are type names and are reserved:
| Type | Description |
|---|---|
i8 | 8-bit signed integer |
i16 | 16-bit signed integer |
i32 | 32-bit signed integer |
i64 | 64-bit signed integer |
u8 | 8-bit unsigned integer |
u16 | 16-bit unsigned integer |
u32 | 32-bit unsigned integer |
u64 | 64-bit unsigned integer |
f32 | IEEE 754 binary32 floating-point (§3.12) |
f64 | IEEE 754 binary64 floating-point (§3.12) |
bool | Boolean type |
type | Compile-time type of types |
Self | The enclosing struct type, within a struct block (§6.4) |