Skip to content

Commit f91b513

Browse files
committedSep 11, 2021
rusting: init
1 parent f12a1cd commit f91b513

File tree

27 files changed

+336
-0
lines changed

27 files changed

+336
-0
lines changed
 

‎rusting/branches/Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rusting/branches/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "branches"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

‎rusting/branches/src/main.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn main() {
2+
let number = 6;
3+
4+
if number % 4 == 0 {
5+
println!("number is divisible by 4")
6+
} else if number % 3 == 0 {
7+
println!("number is divisible by 3")
8+
} else if number % 2 == 0 {
9+
println!("number is divisible by 2")
10+
} else {
11+
println!("number is not divisible by 4, 3, or 2")
12+
}
13+
}

‎rusting/functions/Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rusting/functions/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "functions"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

‎rusting/functions/src/main.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
4+
let x = 5;
5+
6+
let y = {
7+
let x = 3;
8+
x + 1
9+
};
10+
11+
another_function(x, y);
12+
}
13+
14+
fn another_function(x : i32, y: i32) {
15+
println!("The value of x is: {}", x);
16+
println!("The value of y is: {}", y);
17+
}

‎rusting/guessing_game/Cargo.lock

+85
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rusting/guessing_game/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "guessing_game"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
rand = "0.8.3"

‎rusting/guessing_game/src/main.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use std::io;
2+
use std::cmp::Ordering;
3+
use rand::Rng;
4+
5+
fn main() {
6+
println!("Guess the number!");
7+
8+
let secret_number = rand::thread_rng().gen_range(1..101);
9+
10+
// println!("The secret number is: {}", secret_number);
11+
12+
loop {
13+
14+
println!("Please input your guess.");
15+
16+
let mut guess = String::new();
17+
18+
io::stdin()
19+
.read_line(&mut guess)
20+
.expect("Failed to read line");
21+
22+
let guess: u32 = match guess.trim().parse() {
23+
Ok(num) => num,
24+
Err(_) => continue,
25+
};
26+
27+
println!("You guessed: {}", guess);
28+
29+
match guess.cmp(&secret_number) {
30+
Ordering::Less => println!("Too small!"),
31+
Ordering::Greater => println!("Too big!"),
32+
Ordering::Equal => {
33+
println!("You win!");
34+
break;
35+
}
36+
}
37+
}
38+
}

‎rusting/hello_cargo/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

‎rusting/hello_cargo/Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rusting/hello_cargo/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "hello_cargo"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

‎rusting/hello_cargo/src/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

‎rusting/hello_world/main

3.15 MB
Binary file not shown.

‎rusting/hello_world/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello world!");
3+
}

‎rusting/loops/Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rusting/loops/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "loops"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

‎rusting/loops/src/main.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
loop {
3+
println!("again!")
4+
}
5+
}

‎rusting/rectangles/Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rusting/rectangles/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "rectangles"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

‎rusting/rectangles/src/main.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#[derive(Debug)]
2+
struct Rectangle {
3+
width: u32,
4+
height: u32,
5+
}
6+
7+
impl Rectangle {
8+
fn area(&self) -> u32 {
9+
self.width * self.height
10+
}
11+
}
12+
13+
fn main() {
14+
let rect1 = Rectangle {
15+
width: 30,
16+
height: 50,
17+
};
18+
19+
println!("rect1 is {:#?}", rect1);
20+
21+
println!(
22+
"The area of the rectangle is {} square pixels,",
23+
rect1.area()
24+
);
25+
}

‎rusting/restaurant/Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rusting/restaurant/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "restaurant"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

‎rusting/restaurant/src/lib.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
mod front_of_house {
2+
pub mod hosting {
3+
pub fn add_to_waitlist() {}
4+
5+
fn seat_at_table() {}
6+
}
7+
8+
mod serving {
9+
fn take_order() {}
10+
11+
fn serve_order() {}
12+
13+
fn take_payment() {}
14+
}
15+
}
16+
17+
pub fn eat_at_restaurant() {
18+
// Absolute path
19+
crate::front_of_house::hosting::add_to_waitlist();
20+
21+
// Relative path
22+
front_of_house::hosting::add_to_waitlist();
23+
}

‎rusting/variables/Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rusting/variables/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "variables"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

‎rusting/variables/src/main.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {
2+
let x = 5;
3+
4+
let x = x + 1;
5+
6+
let x = x * 2;
7+
8+
println!("The value of x is: {}", x);
9+
}

0 commit comments

Comments
 (0)
Please sign in to comment.