Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

A - Language Reference

Keywords

KeywordDescription
fnDefines a function.
pubMarks a function as publicly exported from the compiled WebAssembly module.
returnReturns a value from a function.
letDeclares a local variable.
mutMakes a variable or function parameter mutable (reassignable).
constDeclares a compile-time constant.
ifBegins a conditional statement.
elseDefines the branch taken when an if condition is false.
loopBegins an infinite or conditional loop.
breakExits the innermost enclosing loop.
trueBoolean literal for the true value.
falseBoolean literal for the false value.
structDefines a user-defined type with named fields.
implDefines methods and associated functions for a type.
selfReferences the current instance in a method.
enumDefines an enumeration type.
typeDefines a type alias.
forallNon-deterministic block where all computation paths are reachable.
existsNon-deterministic block where at least one computation path is reachable.
assumeFilters execution paths inside a non-deterministic block.
uniqueNon-deterministic block where exactly one computation path is reachable.
specSpecification block for formal verification.
externalDeclares an external function.
useImports declarations from another module.
moduleDeclares a module.

Data Types

Data TypeDescription
i88-bit signed integer. Range: -128 to 127.
i1616-bit signed integer. Range: -32,768 to 32,767.
i3232-bit signed integer. Range: -2,147,483,648 to 2,147,483,647.
i6464-bit signed integer. Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
u88-bit unsigned integer. Range: 0 to 255.
u1616-bit unsigned integer. Range: 0 to 65,535.
u3232-bit unsigned integer. Range: 0 to 4,294,967,295.
u6464-bit unsigned integer. Range: 0 to 18,446,744,073,709,551,615.
boolBoolean type. Values: true or false.
[T; N]Fixed-size array of N elements of type T. Both T and N must be known at compile time.
structUser-defined type with named fields. Defined with struct Name { field: Type; ... }.
enumEnumeration type with named variants. Defined with enum Name { Variant1, Variant2, ... }.

Operators

Arithmetic Operators

OperatorDescriptionExample
+Additiona + b
-Subtractiona - b
*Multiplicationa * b
/Divisiona / b
%Remainder (modulo)a % b
-Unary negation-a

Note

Integer arithmetic wraps on overflow. For example, adding 1 to the maximum i32 value wraps around to the minimum i32 value.

Comparison Operators

Comparison operators evaluate to a bool value.

OperatorDescriptionExample
==Equal toa == b
!=Not equal toa != b
<Less thana < b
<=Less than or equal toa <= b
>Greater thana > b
>=Greater than or equal toa >= b

Note

Enum values support only == and !=. Ordering comparisons (<, <=, >, >=) require numeric types.

Logical Operators

Logical operators work on bool values and produce a bool result.

OperatorDescriptionExample
&&Logical ANDa && b
||Logical ORa || b
!Logical NOT (unary)!a

Bitwise Operators

Bitwise operators work on the binary representation of integer values.

OperatorDescriptionExample
&Bitwise ANDa & b
|Bitwise ORa | b
^Bitwise XORa ^ b
~Bitwise NOT (unary complement)~a
<<Left shifta << b
>>Right shifta >> b

Access Operators

OperatorDescriptionExample
.Member access (field or method)point.x, counter.get()
::Type-associated accessPoint::new()