Rust Types

Tuples

let tuple = (1, 'A' , "Cool", 78, true);

Vectors

let some\_vector = vec![1,2,3,4,5]; 

A vector is declared using the vec! macro.

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:?}");

Mutable Array

let mut array: [i32 ; 3] = [2,6,10];
array[1] = 4;
array[2] = 6;

Use the mut keyword to make it mutable.

Multi-Dimensional Array

     j0   j1   j2   j3   j4   j5
   ┌────┬────┬────┬────┬────┬────┐
i0 | 1  | 2  | 3  | 4  | 5  | 6  |
   ├────┼────┼────┼────┼────┼────┤
i1 | 6  | 5  | 4  | 3  | 2  | 1  |
   └────┴────┴────┴────┴────┴────┘

let array: [[i64; 6] ;2] = [
            [1,2,3,4,5,6],
            [6,5,4,3,2,1]];

Arrays

┌─────┬─────┬─────┬─────┬─────┬─────┐
| 92  | 97  | 98  | 99  | 98  | 94  |
└─────┴─────┴─────┴─────┴─────┴─────┘
   0     1     2     3     4     5

let array: [i64; 6] = [92,97,98,99,98,94];

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");

See: Strings

Character

let first\_letter\_of\_alphabet = 'a';
let explicit\_char: char = 'F';
let implicit\_char = '8';
let emoji = "\u{1f600}";   // => 😀

Boolean

let true\_val: bool = true;
let false\_val: bool = false;
let just\_a\_bool = true;
let is\_true = 8 < 5;  // => false

Floating-Point

let mut sixty\_bit\_float: f64 = 89.90;
let thirty\_two\_bit\_float: f32 = 7.90;
let just\_a\_float = 69.69;

Integer

let mut a: u32 = 8;
let b: u64 = 877;
let c: i64 = 8999;
let d = -90;
Comments