Primitives - Rust by Example
Primitives - Rust by Example
Scalar Types
Compound Types
1 fn main() {
2 // Variables can be type annotated.
3 let logical: bool = true;
4
5 let a_float: f64 = 1.0; // Regular a
6 let an_integer = 5i32; // Suffix an
7
8 // Or a default will be used.
9 let default_float = 3.0; // `f64`
10 let default_integer = 7; // `i32`
11
12 // A type can also be inferred from c
13 let mut inferred_type = 12; // Type i
14 inferred_type = 4294967296i64;
15
16 // A mutable variable's value can be
17 let mut mutable = 12; // Mutable `i32
18 mutable = 21;
19
20 // Error! The type of a variable can'
21 mutable = true;
22
23 // Variables can be overwritten with
24 let mutable = true;
25 }
26
See also: