Init commit

This commit is contained in:
mollusk 2019-02-05 07:08:31 -07:00
commit ad9ebb8920
22 changed files with 329 additions and 0 deletions

2
branches/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
**/*.rs.bk

4
branches/Cargo.lock generated Normal file
View File

@ -0,0 +1,4 @@
[[package]]
name = "branches"
version = "0.1.0"

7
branches/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "branches"
version = "0.1.0"
authors = ["mollusk <silvernode@gmail.com>"]
edition = "2018"
[dependencies]

62
branches/src/main.rs Normal file
View File

@ -0,0 +1,62 @@
fn conditionals_test() {
let number = 6;
if number % 4 == 0 {
println!("number is divisible by 4");
} else if number % 3 == 0 {
println!("number is divisible by 3");
} else if number % 2 == 0 {
println!("number is divisible by 2");
} else {
println!("number is not divisible by 4, 3, or 2");
}
let condition = true;
let number = if condition { 5 } else { 6 };
println!("The value of number is: {}", number);
}
fn loop_test(){
loop {
println!("again!");
break
}
}
fn while_loop_test(){
let mut number = 3;
while number != 0 {
println!("{}!", number);
number = number -1;
}
println!("LIFTOFF!!!");
}
fn for_loop_test(){
let a = [10, 20, 30, 40, 50];
let mut index = 0;
for element in a.iter() {
println!("the value is: {}", element);
}
for number in (1..4).rev() {
println!("{}!", number);
}
println!("LIFTOFF!");
}
fn main(){
conditionals_test();
loop_test();
while_loop_test();
for_loop_test();
}

2
functions/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
**/*.rs.bk

4
functions/Cargo.lock generated Normal file
View File

@ -0,0 +1,4 @@
[[package]]
name = "functions"
version = "0.1.0"

7
functions/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "functions"
version = "0.1.0"
authors = ["mollusk <silvernode@gmail.com>"]
edition = "2018"
[dependencies]

30
functions/src/main.rs Normal file
View File

@ -0,0 +1,30 @@
fn main() {
println!("Function 1\n");
another_function(5, 6);
let x = five();
println!("Function 2\n");
println!("The value of x is: {}\n", x);
let x = plus_one(5);
println!("Function 3\n");
println!("The value of x is {}: ", x);
}
fn another_function(x: i32, y: i32) {
println!("The value of x is: {}", x);
println!("The value of y is: {}\n", y);
}
fn five() -> i32 {
5
}
fn plus_one(x: i32) -> i32 {
x + 1
}

2
guessing_game/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
**/*.rs.bk

79
guessing_game/Cargo.lock generated Normal file
View File

@ -0,0 +1,79 @@
[[package]]
name = "fuchsia-cprng"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "guessing_game"
version = "0.1.0"
dependencies = [
"rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rand"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"fuchsia-cprng 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_core"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum fuchsia-cprng 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "81f7f8eb465745ea9b02e2704612a9946a59fa40572086c6fd49d6ddcf30bf31"
"checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047"
"checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0"
"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

9
guessing_game/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "guessing_game"
version = "0.1.0"
authors = ["mollusk <silvernode@gmail.com>"]
edition = "2018"
[dependencies]
rand = "0.4.0"

36
guessing_game/src/main.rs Normal file
View File

@ -0,0 +1,36 @@
use std::io;
use std::cmp::Ordering;
use rand::Rng;
fn main() {
println!("Guess the number!");
let secret_number = rand::thread_rng()
.gen_range(1, 101);
loop {
println!("Please input your guess.");
let mut guess = String::new();
io::stdin().read_line(&mut guess)
.expect("Failed to read line");
let guess: u32 = match guess.trim().parse() {
Ok(num) => num,
Err(_) => continue,
};
println!("You guessed: {}", guess);
match guess.cmp(&secret_number) {
Ordering::Less => println!("Too small!"),
Ordering::Greater => println!("Too big!"),
Ordering::Equal => {
println!("You win!");
break;
}
}
}
}

2
hello_cargo/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
**/*.rs.bk

4
hello_cargo/Cargo.lock generated Normal file
View File

@ -0,0 +1,4 @@
[[package]]
name = "hello_cargo"
version = "0.1.0"

7
hello_cargo/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "hello_cargo"
version = "0.1.0"
authors = ["mollusk <silvernode@gmail.com>"]
edition = "2018"
[dependencies]

3
hello_cargo/src/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

BIN
hello_world/main Executable file

Binary file not shown.

4
hello_world/main.rs Normal file
View File

@ -0,0 +1,4 @@
fn main() {
println!("Hello, World");
}

2
variables/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
**/*.rs.bk

4
variables/Cargo.lock generated Normal file
View File

@ -0,0 +1,4 @@
[[package]]
name = "variable"
version = "0.1.0"

7
variables/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "variable"
version = "0.1.0"
authors = ["mollusk <silvernode@gmail.com>"]
edition = "2018"
[dependencies]

52
variables/src/main.rs Normal file
View File

@ -0,0 +1,52 @@
fn main() {
//manipulate immutable variables
let x = 5;
let x = x + 1;
let x = x * 2;
println!("The value of x is: {}", x);
// addition
let sum = 5 + 10;
// subtraction
let difference = 95.5 - 4.3;
// multiplication
let product = 4 * 30;
// division
let quotient = 56.7 / 32.2;
// remainder
let remainder = 43 % 5;
//bools
let t = true;
let f: bool = false; // with explicit type annotation
//characters
let c = 'z';
let z = '';
let heart_eyed_cat = '😻';
//tuples
let tup = (500, 6.4, 1);
let (x, y, z) = tup;
println!("The value of y is: {}", y);
let x: (i32, f64, u8) = (500, 6.4, 1);
let five_hundred = x.0;
let six_point_four = x.1;
let one = x.2;
}