Rust Tutorial: Data Types
Integers, floats, booleans, and characters — Rust's primitive building blocks.
Primitive types
Every value in Rust has a type known at compile time. The primitives are the simplest building blocks.
What you'll learn in this Rust data types tutorial
This interactive Rust tutorial has 8 hands-on exercises. Estimated time: 15 minutes.
- Integer types — The most common integer is `i32`. Rust also has `i8`, `i16`, `i64`, `i128` and unsigned versions `u8`..`u128`.
- Floating-point — `f64` (double precision) is the default float type. Use `f32` only when memory is critical.
- Integer arithmetic — Standard operators: `+`, `-`, `*`, `/`, `%`. Integer division truncates.
- Boolean type — A `bool` is `true` or `false`. Comparison operators produce booleans.
- The char type — A `char` uses single quotes and stores a single Unicode scalar value — including emoji.
- Type conversion with as — Rust never converts types implicitly. Use `as` to convert between numerics.
- Overflow behaviour — In debug mode, integer overflow panics. In release mode it wraps.
- Numeric methods — Numbers have built-in methods. Explore a few.
Rust Data Types concepts covered
- Primitive types