# git - personal account Use GitHub Desktop to do checkins from personal account! # create a new project cargo new # build a project cd cargo build # run a debug project ./target/debug/.exe OR cargo run # adding new packages => update cargo.toml [dependencies] section with new packages => run cargo update # variables let mut = ; # user entry use std::io; io::stdin().real_line(&mut line).expect() # output println!(, ) # with string interpolation let x = 5; let y = 10; println!("x = {x} and y + 2 = {}", y + 2); # random numbers [dependencies] rand = "0.8.5" use rand::Rng; rand::thread_rng().gen_range(1..=100) # comparisons use std::cmp::Ordering; match .cmp(&) { Ordering::Less => ..., Ordering::Greater => ..., Ordering::Equal => ..., } # string manipulation let num: u32 = .trim().parse.expect(); # conditional - if if { ... } else { ... } # pseudo-ternary let number = if condition { 1 } else { 2 }; # loops loop { ... break; } # with values let result = loop { ... break ; } # with labels 'outer': loop { ... loop { ... break 'outer'; } } # while while { ... } # iterating collections let a = [1,2,3,4,5] for item in a { ... } # data types ## scalars - int, float, num, bool, char ## int - signed / unsigned i/u 8,16,32,64,128,size ## float - f 32,64 ## bool - true, false ## char - letters, numbers, characters, including emoji!! (use single quotes and strings use double quotes) ## compound types - tuple ## tuple - let (, , ) = (, , ); ## array - let a = [, , ]; let a: [i32; 5] = [1,2,3,4,5]; let a = [3; 5]; ### range - (1...100) ### other array tricks, .rev() # functions fn (: , : ) { } # "statements" - functions that do not return a value # "expressions" - evaluate to a return value ## with return values - returns value of last expression in function fn () -> { } # comments - double forward slash //