update
This commit is contained in:
1
restaurant/.gitignore
vendored
Normal file
1
restaurant/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
target/
|
||||
7
restaurant/Cargo.lock
generated
Normal file
7
restaurant/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "restaurant"
|
||||
version = "0.1.0"
|
||||
6
restaurant/Cargo.toml
Normal file
6
restaurant/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "restaurant"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
16
restaurant/src/lib.rs
Normal file
16
restaurant/src/lib.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
mod front_of_house {
|
||||
mod hosting {
|
||||
fn add_to_waitlist() {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
fn seat_at_table() {}
|
||||
}
|
||||
mod serving {
|
||||
fn take_order() {}
|
||||
fn serve_order() {}
|
||||
fn take_payment() {}
|
||||
}
|
||||
}
|
||||
1
shirt_company/rust/.gitignore
vendored
Normal file
1
shirt_company/rust/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
target/
|
||||
7
shirt_company/rust/Cargo.lock
generated
Normal file
7
shirt_company/rust/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
6
shirt_company/rust/Cargo.toml
Normal file
6
shirt_company/rust/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
81
shirt_company/rust/src/main.rs
Normal file
81
shirt_company/rust/src/main.rs
Normal file
@@ -0,0 +1,81 @@
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
enum ShirtColor {
|
||||
Red,
|
||||
Blue,
|
||||
}
|
||||
struct Inventory {
|
||||
shirts:Vec<ShirtColor>,
|
||||
}
|
||||
impl Inventory {
|
||||
fn giveaway(
|
||||
&self,
|
||||
user_preference: Option<ShirtColor>,
|
||||
) -> ShirtColor {
|
||||
user_preference.unwrap_or_else(|| self.most_stocked())
|
||||
}
|
||||
fn most_stocked(&self) -> ShirtColor {
|
||||
let mut num_red = 0;
|
||||
let mut num_blue = 0;
|
||||
for color in &self.shirts {
|
||||
match color {
|
||||
ShirtColor::Red => num_red += 1,
|
||||
ShirtColor::Blue => num_blue += 1,
|
||||
}
|
||||
}
|
||||
if num_red > num_blue {
|
||||
ShirtColor::Red
|
||||
} else {
|
||||
ShirtColor::Blue
|
||||
}
|
||||
}
|
||||
}
|
||||
fn main() {
|
||||
let store = Inventory {
|
||||
shirts: vec![
|
||||
ShirtColor::Blue,
|
||||
ShirtColor::Red,
|
||||
ShirtColor::Blue,
|
||||
],
|
||||
};
|
||||
let user_pref1 = Some(ShirtColor::Red);
|
||||
let giveaway1 = store.giveaway(user_pref1);
|
||||
println!(
|
||||
"The user with preference {:?} gets {:?}",
|
||||
user_pref1, giveaway1
|
||||
);
|
||||
let user_pref2 = None;
|
||||
let giveaway2 = store.giveaway(user_pref2);
|
||||
println!(
|
||||
"The user with preference {:?} gets {:?}",
|
||||
user_pref2, giveaway2
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user