Rust Data Types
Rust Data Types
Data types define the kind of value a variable can store.
Rust is a statically typed language, which means the compiler knows the type of every variable at compile time.
let age = 20;
let price = 99.99;
let is_active = true;
Rust mainly provides two categories of data types:
- Scalar Data Types
- Compound Data Types
Video Explanation

1. Scalar Data Types
Scalar data types store a single value.
Rust provides four main scalar types:
- Integer
- Floating Point
- Boolean
- Character
Integer Types
Integer types are used to store whole numbers.
Rust supports both signed and unsigned integers.
- Signed integers can store positive and negative values.
- Unsigned integers store only positive values.
| Type | Size | Example |
|---|---|---|
| i8 | 8-bit | -10 |
| u8 | 8-bit | 10 |
| i16 | 16-bit | -200 |
| u16 | 16-bit | 200 |
| i32 | 32-bit | -500 |
| u32 | 32-bit | 500 |
| i64 | 64-bit | -9000 |
| u64 | 64-bit | 9000 |
| i128 | 128-bit | -100000 |
| u128 | 128-bit | 100000 |
| isize | arch-dependent | -1 |
| usize | arch-dependent | 1 |
i32 is the default integer type in Rust.
Example
fn main() {
let age: u8 = 20;
let temperature: i32 = -15;
println!("Age: {}", age);
println!("Temperature: {}", temperature);
}
Output
Age: 20
Temperature: -15
Floating Point Types
Floating point types are used to store decimal values.
Rust provides two floating point types:
| Type | Size | Example |
|---|---|---|
| f32 | 32-bit | 3.14 |
| f64 | 64-bit | 99.99 |
f64 is the default floating point type.