Skip to content

First steps

var declares a mutable binding; let is reserved for pattern- binding (covered later). Annotate the type, or let the checker infer it from the initialiser.

open in playground →

There’s no untyped int. The eight integer types are i8, i16, i32, i64 (signed) and u8, u16, u32, u64 (unsigned), plus usize for native pointer-width counts. Two floats: f32 and f64. Mixing widths needs an explicit cast.

var a: i32 = 7;
var b: i64 = a as i64; // narrow → wide cast
var c: i32 = b as i32; // wide → narrow (may truncate)

if / else, while, and three-part for.

open in playground →

if is also an expression, for one-line ternaries.

var max: i32 = if (a > b) { a } else { b };
function add(a: i32, b: i32): i32 {
return a + b;
}

Return and parameter types are always required — even void for procedures. There’s no inference at the signature boundary.

Next: Types →