3 Rust provides access to a wide variety of `primitives`. A sample includes:
8 * signed integers: `i8`, `i16`, `i32`, `i64`, `i128` and `isize` (pointer size)
9 * unsigned integers: `u8`, `u16`, `u32`, `u64`, `u128` and `usize` (pointer
11 * floating point: `f32`, `f64`
12 * `char` Unicode scalar values like `'a'`, `'α'` and `'∞'` (4 bytes each)
13 * `bool` either `true` or `false`
14 * and the unit type `()`, whose only possible value is an empty tuple: `()`
16 Despite the value of a unit type being a tuple, it is not considered a
17 compound type because it does not contain multiple values.
21 * arrays like `[1, 2, 3]`
22 * tuples like `(1, true)`
24 Variables can always be *type annotated*. Numbers may additionally be
25 annotated via a *suffix* or *by default*. Integers default to `i32` and
26 floats to `f64`. Note that Rust can also infer types from context.
28 ```rust,editable,ignore,mdbook-runnable
30 // Variables can be type annotated.
31 let logical: bool = true;
33 let a_float: f64 = 1.0; // Regular annotation
34 let an_integer = 5i32; // Suffix annotation
36 // Or a default will be used.
37 let default_float = 3.0; // `f64`
38 let default_integer = 7; // `i32`
40 // A type can also be inferred from context
41 let mut inferred_type = 12; // Type i64 is inferred from another line
42 inferred_type = 4294967296i64;
44 // A mutable variable's value can be changed.
45 let mut mutable = 12; // Mutable `i32`
48 // Error! The type of a variable can't be changed.
51 // Variables can be overwritten with shadowing.
58 [the `std` library][std], [`mut`][mut], [inference], and [shadowing]
60 [std]: https://doc.rust-lang.org/std/
61 [mut]: variable_bindings/mut.html
62 [inference]: types/inference.html
63 [shadowing]: variable_bindings/scope.html