Skip to content

Commit

Permalink
210918
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoloves committed Sep 18, 2021
1 parent 6626d1d commit 245e23b
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rust_project/enumSmp/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions rust_project/enumSmp/Cargo.toml
@@ -0,0 +1,8 @@
[package]
name = "enumSmp"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
27 changes: 27 additions & 0 deletions rust_project/enumSmp/src/main.rs
@@ -0,0 +1,27 @@
fn main() {
enum Coin {
Penny,
Nickel,
Dime,
Quarter,
}


fn value_in_cents(coin: Coin) -> u32 {
match coin {
Coin::Penny => {
println!("Lucky penny!");
1
},
Coin::Nickel => 5,
Coin::Dime => 10,
Coin::Quarter => 25,
}
}

let some_u8_value = Some(0u8);
match some_u8_value {
Some(3) => println!("three"),
_ => (),
}
}
72 changes: 72 additions & 0 deletions rust_project/rectangles/src/main.rs
@@ -1,3 +1,70 @@
#[derive(Debug)]

struct Rectangle {
width: u32,
height: u32,
}

impl Rectangle {
fn area4(&self) -> u32 {
self.width * self.height
}

fn can_hold(&self, other: other: &Rectangle) -> bool {
self.width > other.width && self.height > other.height
}
}

fn smp_main5() {
let rect1 = Rectangle { width: 30, height: 50 };
let rect2 = Rectangle { width: 10, height: 40 };
let rect3 = Rectangle { width: 60, height: 45 };

println!("Can rect 1 hold rect2? {}", rect1.can_hold(&rect2))
println!("Can rect 1 hold rect3? {}", rect1.can_hold(&rect3))
}

fn smp_main4() {
let rect1 = Rectangle { width: 30, height: 50 };

println!(
"The area of the rectangle is {} suare pixels.",
rect1.area4()
);
}

fn smp_main3() {
let rect1 = Rectangle { width: 30, height: 50};

println!("rect1 is {:?}", rect1);
}

fn smp_main2() {
let rect1 = Rectangle { width: 30, height: 50};

println!(
"The area of the rectangle is {} square pixels.",
area3(&rect1)
);
}

fn area3(rectangle: &Rectangle) -> u32 {
rectangle.width * rectangle.height
}

fn smp_main() {
let rect1 = (30, 50);

println!(
"The area of the rectangle is {} square pixels.",
area2(rect1)
)
}

fn area2(dimensions: (u32, u32)) -> u32 {
dimensions.0 * dimensions.1
}

fn area(width: u32, height: u32) -> u32 {
width * height
}
Expand All @@ -10,5 +77,10 @@ fn main() {
"The area of the rectangle is {} square pixels.",
area(width1, height1)
);

smp_main();
smp_main2();
smp_main3();
smp_main4();
}

0 comments on commit 245e23b

Please sign in to comment.