The Tessera Book
Appendix A

Keywords and Operators

Keywords

These words are reserved and can't be used as names:

KeywordUse
fndeclare a function or method
let, mutdeclare a variable; make it changeable
if, elsechoose between branches
matchchoose by pattern
for, in, whileloop
break, continueleave a loop; start its next round
returnleave a function with a value
struct, enumdeclare a type
interface, dyndeclare an interface; a value of any type that satisfies one
pubexport an item from its module
usebring in a module
grouprun tasks that finish when the block ends
selectwait for one of several channel operations
deferrun a statement when the block is left
true, falsethe two Bool values

These words have a meaning only in their own place (where they start their construct, or after a pattern for as), so they remain usable as names elsewhere (a field can be called type):

WordUse
typedeclare a type alias: type Counts = Map[Str, Int]
test, benchdeclare a test or a benchmark
foreigndeclare C functions
withcopy a struct with changes: { p with x: 1 }
untilgive a group a deadline
interleavedlet a group's tasks print as they go
virtuala test clock on virtual time
asin a pattern, also bind the whole value: Some(p) as whole

Operators

From loosest to tightest binding. All binary operators are left-associative.

LevelOperatorsMeaning
1|>pipe: x |> f(a) is f(x, a)
2||or, short-circuit
3&&and, short-circuit
4== !=equal, not equal (structural)
5< <= > >=compare ordered values
6..<range: lo..<hi
7+ - | ^add, subtract, bitwise or, exclusive or; + also joins Str, Bytes and lists
8* / % & << >>multiply, divide, remainder, bitwise and, shift left, shift right keeping the sign
9??the value in Some or Ok, or a default
10- ! ~negate, not, flip every bit
11f(x) a[i] p.x a?.b e?call, index, field or method, safe navigation, early return

Both operands of a binary operator must have the same type: there are no implicit conversions.

The bitwise operators work on Int. Because & binds like * and | like +, x & 1 == 0 is (x & 1) == 0, and a + b << 2 is a + (b << 2). A shift by 64 or more moves every bit out (0, or -1 for >> of a negative number); a negative shift count panics. x.shift_right_unsigned(n) shifts right filling with zeros.

Other symbols

SymbolMeaning
->a function's result type
=>separates a pattern from its arm in match and select
|x| expra closure
? after an expressionreturn early on None or Err
? "text"the same, adding context to the error
?.safe navigation on an Option
{ ... } inside a stringinterpolation; \{ for a literal brace
//a comment, to the end of the line
_a pattern that matches anything; a name for a value you don't need
p1 | p2 in a patternan or-pattern: matches when either alternative does
.. in a patternthe items not written out: Request(method, ..), (first, ..), [.., last]
..name in a list patternthe items not written out, as a new list: [first, ..rest]
[p1, p2] in a patterna list of exactly those items
Point { x, y: 0 } in a patterna struct, by its fields; x alone binds the field x; .. at the end skips the rest
p as name in a patternwhat p matches, with the whole value bound to name
(a, b) = valueassign a tuple's items to existing mut variables

Error codes

Every compiler diagnostic has a code, such as E0302. tessera explain CODE describes it, and tessera check --json reports codes, positions, notes and automatic fixes for tools. Codes from E0001 are about syntax, from E0101 names and types, from E0201 type checking, from E0301 capabilities and concurrency, from E0320 packages, from E0330 foreign functions, and from E0401 modules. Codes starting with W are warnings.