diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..09230bc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.readonlyInclude": { + "**/.cargo/registry/src/**/*.rs": true, + "**/lib/rustlib/src/rust/library/**/*.rs": true, + } +} \ No newline at end of file diff --git a/cheatsheet.txt b/cheatsheet.txt new file mode 100644 index 0000000..8274811 --- /dev/null +++ b/cheatsheet.txt @@ -0,0 +1,112 @@ +# 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 // \ No newline at end of file diff --git a/day01/Cargo.toml b/day01/Cargo.toml new file mode 100644 index 0000000..e7d55b7 --- /dev/null +++ b/day01/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "day01" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/day01/src/main.rs b/day01/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/day01/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/main.rs b/main.rs new file mode 100644 index 0000000..d10dce9 --- /dev/null +++ b/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello world!"); +} \ No newline at end of file