Data Types
Rust is a systems programming language focused on speed, memory safety, and fearless concurrency — and because it is statically typed, every value has a known type at compile time.
Learn Data Types in our free Rust course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick reference.
Part of the free Rust course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
In this lesson you'll meet Rust's scalar types (integers, floats, booleans, chars) and its compound types (tuples and arrays), and learn how the compiler infers and checks them.
What You'll Learn in This Lesson
1️⃣ Scalar Types: Numbers, Booleans, and Chars
Scalar types represent a single value. Rust has four families: integers (whole numbers like i32 and u8 ), floating-point numbers (decimals like f64 ), booleans ( true / false ), and characters (a single Unicode value in single quotes). You can let Rust infer the type or annotate it explicitly with a colon.
The letter i or u tells you signed or unsigned, and the number tells you the bit width. When you don't annotate, integers default to i32 and floats to f64 .
2️⃣ Compound Types: Tuples and Arrays
Compound types bundle several values into one. A tuple holds a fixed number of values that can be different types, accessed by position ( .0 , .1 ). An array holds a fixed number of values that are all the same type, accessed by index ( [0] ). You can also destructure a tuple into separate names.
Both tuples and arrays have a fixed length known at compile time. For a growable list you'd reach for a Vec , which you'll meet later. Notice {' '} printed the whole array at once.
Your turn. Fill in the blanks marked ___ , then run it.
Write it yourself from the outline and run it with cargo run . You'll combine a tuple, destructuring, and an array.
📋 Quick Reference — Data Types
Practice quiz
What is Rust's default integer type when none is annotated?
- u8
- i64
- i32
- usize
Answer: i32. Integers default to i32, which is usually the fastest on modern hardware.
What does the u in u8 mean?
- Unsigned (no negatives)
- Universal
- Unicode
- Unsafe
Answer: Unsigned (no negatives). u means unsigned, so a u8 holds 0 to 255 with no negative values.
What is the largest value a u8 can hold?
- 256
- 127
- 1024
- 255
Answer: 255. A u8 is 8 bits, holding 0 through 255 inclusive.
What is the default floating-point type in Rust?
- f32
- f64
- float
- double
Answer: f64. Floats default to f64, which is double precision.
How many bytes does a Rust char occupy?
- 4
- 1
- 2
- 8
Answer: 4. A char is a Unicode scalar value stored in 4 bytes, not 1 like C.
Which quotes denote a single char literal?
- Double quotes, like "R"
- Backticks
- Single quotes, like 'R'
- No quotes
Answer: Single quotes, like 'R'. 'R' is a char; "R" is a string slice.
What can hold a single emoji like the crab in Rust?
- A u8
- A char
- A bool
- An i32
Answer: A char. A char holds any Unicode scalar value, including emoji.
How do you access the first element of an array a?
- a.0
- a.first
- a(0)
Arrays are indexed with square brackets starting at 0; tuples use .0 instead.
What does the {:?} placeholder do in println!?
- Prints nothing
- Prints using Debug formatting
- Rounds floats
- Escapes quotes
Answer: Prints using Debug formatting. {:?} uses Debug formatting and can print whole structures like arrays.
Which type should you use for indexing collections?
- i32
- u8
- usize
- f64
Answer: usize. usize is sized to the machine's pointer width and is used for indexing.