typestar

Variables and mutability in Rust

Bindings are immutable by default; mut opts in.

fn main() {
    let name = "typestar";
    let count: i32 = 42;
    let ratio = 3.5_f64;

    let mut total = 0;
    total += count;
    total *= 2;

    let doubled = ratio * 2.0;
    println!("{name}: {total} ({doubled})");
}

How it works

  1. let binds a value; a type can be annotated or inferred.
  2. mut is required before a binding can change.
  3. += and *= update a mutable binding.

Keywords and builtins used here

The run, in numbers

Lines
12
Characters to type
195
Tokens
56
Three-star pace
80 tpm

At the three-star pace of 80 tokens a minute, this run takes about 42 seconds.

Type this snippet

Step 1 of 6 in Variables & types, step 1 of 39 in Language basics.

Next →