Tsallaka zuwa abun ciki
Justice Tech School

Variables and Types

Variables are immutable by default. Add mut to change them. Shadowing re-declares a name. Types include i32, u8, f64, bool, char and String.

Example
let x = 5;
let mut y = 10;
y += x;
let name: &str = "Ada";
let pi: f64 = 3.14;
let x = x * 2;
println!("{} {} {} {}", x, y, name, pi);
const MAX: u32 = 100;
println!("{}", MAX);

Result

10 15 Ada 3.14
100

Exercise

Allow a variable to change.

let  n = 1;

Quiz Test

Are Rust variables mutable by default?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.