Learning-Rust

Rust is to be installed using official cargo distribution.

Rustlings course

TIP

Installed with cargo install rustlings and initialised with rustlings init

Intro

Lines are printed with println!() and the main function is defined as fn main().

fn main(){
    println!("Hello World!");
}

Variables

Variables are declared with let keyword and the type is defined with :. Mutable variables need to be defined with mut keyword. Same variable can be reused by changing its type.

fn main(){
    let num = "THREE";
    println!("The number is {num}");
    let mut num:i32 = 10;
    println!("The number is {num}");
    num = 100;
    println!("The number is {num}");
}

Functions

fn call_me(num: i32) -> i32 {
    return num*num;
}
fn main(){
    let square  = call_me(32);
    println!("The square of 32 is {square}");
}