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 integersu32, u64
– Unsigned integersf32, f64
– Floating-point numbersbool
– Boolean (true
orfalse
)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.