Rust provides four fundamental scalar types: integers, floating-point numbers, booleans, and 4-byte Unicode scalar characters, each with deterministic bit widths.
fn main() {
let port: u16 = 8080; // 2 bytes unsigned
let latency: f64 = 0.042; // 8 bytes double precision
let is_connected: bool = true; // 1 byte boolean
let ferris: char = '🦀'; // 4 bytes Unicode scalar
println!("Port: {} (size: {}B)", port, std::mem::size_of_val(&port));
println!("Latency: {} ms (size: {}B)", latency, std::mem::size_of_val(&latency));
println!("Status: {} (size: {}B)", is_connected, std::mem::size_of_val(&is_connected));
println!("Mascot: {} (size: {}B)", ferris, std::mem::size_of_val(&ferris));
}Unlike languages with platform-dependent `int` or `long` sizes, Rust specifies exact bit widths for every primitive type. The only exceptions are `isize` and `usize`, which reflect the host CPU pointer width (64 bits on x86_64, 32 bits on ARMv7).
In debug mode, Rust instruments code with integer overflow detection, triggering an immediate panic. In release builds (`--release`), two's complement wrapping is applied unless explicit methods like `.checked_add()` are used.
Rust gives you explicit arithmetic control: wrapping methods (e.g. `wrapping_add`), checked methods returning `Option<T>` (e.g. `checked_add`), saturating methods capping at min/max (e.g. `saturating_add`), and overflowing methods returning a tuple `(result, did_overflow)`.
let max = u8::MAX; // 255
let wrapped = max.wrapping_add(1); // 0
let checked = max.checked_add(1); // None
let saturating = max.saturating_add(1); // 255