Reading The Rust Book from cover to cover — Day 3 — Scalar Data Types

Jaspreet Kaur
3 min readApr 8, 2024
Rust Logo

Data Types in Rust

Rust is a strongly typed language so it must know the data type of all variables at compile type. The Rust compiler can usually infer the variable type from the value but in cases where it can’t, a type annotation should be added otherwise “type annotations needed” compile error will be thrown. Example syntax:

let guess: u32 = "42".parse().expect("Not a number!");
//in above line u32 is type annotation

Two data type subsets: scalar and compound, this article is a summary of Scalar Types from The Rust Book.

Scalar Types

A scalar type represents a single value. There are 4 scalar types in Rust — integer, floating point numbers, Booleans, and characters.

Integer types:

unsigned integer types start with the letter u and signed integer types start with the letter i

Length    Signed   Unsigned
8-bit i8 u8
16-bit i16 u16
32-bit i32 u32
64-bit i64 u64
128-bit i128 u128
arch isize usize

Each signed variant can store numbers from -(2n — 1) to 2n — 1–1 inclusive, where n is the…

--

--