Primitive Data Types

Rust is a statically typed language, meaning the compiler must know the types of all variables at compile time. Here are the most common primitive types:

Scalar Types

  • i32, i64 – Signed integers
  • u32, u64 – Unsigned integers
  • f32, f64 – Floating-point numbers
  • bool – Boolean (true or false)
  • char – A single Unicode scalar value (e.g., 'A')

Compound Types

  • Tuple – Groups values of different types:
let tup: (i32, f64, u8) = (500, 6.4, 1);
let (x, y, z) = tup;
  • Array – Fixed-size collection of values:
let arr = [1, 2, 3, 4, 5];
let first = arr[0];

Use type annotations when needed, especially in complex or ambiguous cases.

← PrevNext →