Module auto-imported

Keywords

Keywords are recognized by position. Contextual keywords such as self, result, old or from are only special where their page says, and stay ordinary identifiers elsewhere. Avoid using any of them as a name anyway: true, false and typeof always parse as keywords in an expression.

Built into the compiler.

Keywords#

NameDescription
fnDeclares a function, a method, or (written in an expression) an anonymous function.
letDeclares a mutable local variable.
constDeclares a binding that cannot be reassigned: a local, a module constant, or a class field that is set only by new.
staticDeclares a module-level or class-level slot shared by the whole program, or a method without self.
readonlyA read-only view of a value: nothing reachable through it can be changed.
ifRuns a block when a bool condition is true.
elseIntroduces the branch of an if that runs when its condition is false (or its pattern does not match).
whileRepeats a block while a bool condition is true.
forIterates over the values of an array, Vec, range, coroutine or any IntoIterator.
inSeparates the loop variable from the iterated value in a for loop.
breakLeaves the innermost while or for loop at once.
continueSkips the rest of the current iteration and goes on with the next one.
returnLeaves the current function, optionally with a value.
raiseReturns early from the current function with Result::Err(e).
panicAborts with a message: panic "message".
typeofGives the static type of an expression as a string, at compile time.
comptimeComputes an expression while compiling; the program gets its value.
enumDeclares a sum type: a value is exactly one of its variants.
matchCompares a value against patterns and evaluates the first arm that matches.
defaultThe catch-all arm of a match: default => ….
typeDeclares a type alias, or an associated type in a trait or impl.
useImports items from a module, or lists the outer variables a lambda or defer captures.
asRenames an import, or converts a value between primitive types.
modLoads a module file without importing any of its names: mod name;.
externBinds C functions from a native library at compile time: extern "lib" { fn …; }.
classDeclares a class: a named heap type with fields, constructed with new.
implAdds methods to a type (impl Type { … }) or implements a trait for it (impl Trait for Type { … }).
pubMakes a class field or method accessible from outside the type.
newConstructs a class instance: new Class(args).
deferSchedules a block to run when the enclosing function exits.
trueThe bool value true.
falseThe bool value false.
genDeclares a generator function (a coroutine): gen fn name(…) { … }.
asyncRemoved.
yieldSuspends a generator and hands a value to the code that resumed it.
resumeRuns a coroutine until its next yield or its end, and gives the yielded or returned value.
withSends a value into a coroutine as part of resume: resume h with value.
whereAdds trait constraints to a generic function: where Trait<A, B>.
pureDeclares that a function has no effects: pure fn name(…).
usesDeclares the effects a function may have: uses {read, write}.
requiresStates a precondition, checked when the function is entered: requires cond, "message".
ensuresStates a postcondition, checked on every return: ensures cond, "message".
invariantStates a condition that must always hold for a class’s instances, or each time a loop tests its condition.
decreasesStates an int that every iteration of a while loop makes smaller, without going negative.
traitDeclares a trait: a set of functions that types implement with impl Trait for Type.
testDeclares a test case run by coil test: test("name") { … }.
forallWrites a polymorphic (higher-rank) function type: forall T. T -> T.
fromDelegates a generator to another coroutine: yield from other().
structDeclares a C struct layout for FFI: extern struct Name { field: type, … };.
attrDeclares an attribute macro: attr name(FnDecl f, …) -> Code { … }.
deriveDeclares a derive macro: derive Name(TypeDecl t) -> Code { … }, used as #[derive(Name)].
macroDeclares a function-style macro: macro name(Expr a, …) -> Code { … }, used as name!(…).
quoteBuilds generated code inside a macro: quote items|expr|stmts|type { template }.
attrsLists the field and variant attributes a derive macro owns: derive Name(TypeDecl t) -> Code attrs(names) { … }.
doneTells whether a coroutine has finished: done(handle) returns a bool.
selfThe receiver of a method: the instance the method was called on.
resultThe value being returned, inside an ensures clause.
oldThe value an expression had when the function was entered, inside an ensures clause: old(e).
ConstraintThe kind of a constraint, in a kind annotation: c: * -> Constraint.
↑ ↓ navigate ↵ open