Skip to content

Quick Reference ​

Constructs ​

ConceptSyntax
Immutable bindinglet x = 42
Mutable bindingvar x = 42
Type annotationlet x: i32 = 42
Functionfn name(a: i32): i32 { ... }
Generic functionfn name<T>(x: T): T { ... }
Generic bound<T: Eq + Hash>
Reference paramfn f(x: &T) is called f(x); fn f(x: &mut T) is called f(&mut x)
Structstruct Name { field: Type }
Enumenum Name { Variant(Type), Empty }
Matchmatch val { Name.Variant(x) => { ... } }
If letif let Some(x) = opt { ... }
Vecvar v: Vec<i32> = Vec.new()
HashMapvar m: HashMap<K, V> = HashMap.new()
HeapHeap(value), deref with *heaped
Importfrom "path" import { A, B }
FFIextern fn name(args): ret
Traittrait Name { fn method(self: &Self): T }
Impl traitimpl Trait for Type { ... }
Impl methodsimpl Type { ... }
Castexpr as Type
JSON serializejsonStringify(struct_val)
Number to stringn.toString()
Hex / binary literal0xFF, 0b1010

For every reserved word see Keywords; for @ attributes see Annotations & builtins.

Operators and punctuation ​

Generated from the compiler's token table by scripts/gen-lang-docs.ts.

TokenMeaning
(Grouping, a call's arguments, a parameter list.
)Closes (.
{A block, a struct literal, a declaration body.
}Closes {.
[An array literal [1, 2, 3] or [0; 100], an index v[i], a slice s[a..b].
]Closes [.
:Type annotation let x: i32, a parameter's type, a return type fn f(): i32, a struct field Point { x: 1 }.
;Optional statement separator; the count in an array repeat [0; 100].
,Separates arguments, parameters, fields, elements.
.Field access, method call, and paths: Option.Some, Vec.new().
->Not used by the grammar: a return type follows :.
*Multiply; a raw pointer type *T; deref *p (unsafe for a raw pointer).
+Add; string concatenation.
-Subtract; negate.
/Divide.
%Remainder.
&Bitwise and; a reference parameter type &T / &mut T; the &mut x argument marker. &x as an expression is an error: shared borrows are implicit, f(x).
&&Logical and (short-circuit).
||Logical or (short-circuit).
=Assignment and binding.
==Equal.
=>A match arm Pat => expr; a closure body (x: i32) => x * 2.
::Not used by the grammar: paths use ., as in Option.Some.
!=Not equal.
<Less than; opens type arguments Vec<T>; two adjacent, <<, shift left.
>Greater than; closes type arguments; two adjacent, >>, shift right.
<=Less than or equal.
>=Greater than or equal.
!Logical not; postfix unwrap expr! (traps on None or Err); @!wrapping applies an attribute to the whole file.
..Range 0..n (end excluded), a slice s[a..b], a range-constrained integer type i32(0..100).
...Variadic tail of an extern fn parameter list.
?Postfix propagate expr? (returns None or Err early); T? is Option<T>; ?&T is the nullable extern reference.
??Default: opt ?? fallback.
|Bitwise or.
^Bitwise xor.
~Bitwise not.
@An attribute @derive(Eq), or a builtin sigil @embedFile("path").
+=Add and assign.
-=Subtract and assign.
*=Multiply and assign.
/=Divide and assign.
%=Remainder and assign.
&=Bitwise and, and assign.
|=Bitwise or, and assign.
^=Bitwise xor, and assign.

Primitive types ​

Width, signedness and aliases as the type checker resolves them.

TypeKindBitsNote
i8signed integer8
i16signed integer16
i32signed integer32
i64signed integer64
intsigned integer64alias of i64
u8unsigned integer8
byteunsigned integer8alias of u8
u16unsigned integer16
u32unsigned integer32
u64unsigned integer64
f32floating point32
f64floating point64
floatfloating point64alias of f64
booltrue or false
voidno value
stringowned UTF-8 string