Back to Blog

Rust Variables & Data Types Tutorial | Learn Rust Basics for Beginners (2026)

Sandy LaneSandy Lane

Video: Rust Variables & Data Types Tutorial | Learn Rust Basics for Beginners (2026) by Taught by Celeste AI - AI Coding Coach

Watch full page →

Rust Variables & Data Types Tutorial

In Rust, variables are immutable by default, meaning their values cannot be changed once set. To allow modification, you must declare variables as mutable using the mut keyword. Rust also has strong static typing with common data types like integers, floating-point numbers, booleans, and string slices.

Code

// Immutable variable (default)
let x = 5;

// Mutable variable can be changed
let mut y = 10;
y = 20;  // This works because y is mutable

// Explicit data types
let age: i32 = 25;           // 32-bit signed integer
let price: f64 = 19.99;      // 64-bit floating point
let is_rust_fun: bool = true; // Boolean value
let language: &str = "Rust";  // String slice (immutable reference)

// Arithmetic operations
let a = 10;
let b = 3;

let sum = a + b;        // 13
let difference = a - b; // 7
let product = a * b;    // 30
let quotient = a / b;   // 3 (integer division, decimals truncated)
let remainder = a % b;  // 1 (modulo operator gives remainder)

Key Points

  • Variables are immutable by default; use mut to make them mutable.
  • Rust is strongly typed, requiring explicit or inferred data types like i32, f64, bool, and &str.
  • Integer division truncates decimal parts instead of rounding.
  • The modulo operator (%) returns the remainder of division.
  • String slices (&str) represent immutable references to string data.