Types
Integer
Floating-Point
let mut sixty_bit_float: f64 = 89.90;
let thirty_two_bit_float: f32 = 7.90;
let just_a_float = 69.69;
Boolean
let true_val: bool = true;
let false_val: bool = false;
let just_a_bool = true;
let is_true = 8 < 5; // => false
Character
let first_letter_of_alphabet = 'a';
let explicit_char: char = 'F';
let implicit_char = '8';
let emoji = "\u{1f600}"; // => 😀
String Literal
let community_name = "AXIAL";
let no_of_members: &str = "ten";
println!("The name of the community is {community_name} and it has {no_of_members} members");
Arrays
┌─────┬─────┬─────┬─────┬─────┬─────┐
| 92 | 97 | 98 | 99 | 98 | 94 |
└─────┴─────┴─────┴─────┴─────┴─────┘
0 1 2 3 4 5
Multi-Dimensional Array
j0 j1 j2 j3 j4 j5
┌────┬────┬────┬────┬────┬────┐
i0 | 1 | 2 | 3 | 4 | 5 | 6 |
├────┼────┼────┼────┼────┼────┤
i1 | 6 | 5 | 4 | 3 | 2 | 1 |
└────┴────┴────┴────┴────┴────┘
Mutable Array
Use the mut keyword to make it mutable.
Slices
let mut array: [i64; 4] = [1, 2, 3, 4];
let mut slices: &[i64] = &array[0..3]; // Lower range is inclusive and upper range is exclusive
println!("The elements of the slices are : {slices:?}");
Vectors
A vector is declared using the vec! macro.