diff options
Diffstat (limited to 'restaurant')
-rw-r--r-- | restaurant/.gitignore | 18 | ||||
-rw-r--r-- | restaurant/Cargo.toml | 9 | ||||
-rw-r--r-- | restaurant/src/lib.rs | 77 | ||||
-rw-r--r-- | restaurant/src/main.rs | 4 |
4 files changed, 108 insertions, 0 deletions
diff --git a/restaurant/.gitignore b/restaurant/.gitignore new file mode 100644 index 0000000..e629269 --- /dev/null +++ b/restaurant/.gitignore @@ -0,0 +1,18 @@ + +# Created by https://www.toptal.com/developers/gitignore/api/rust +# Edit at https://www.toptal.com/developers/gitignore?templates=rust + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# End of https://www.toptal.com/developers/gitignore/api/rust + diff --git a/restaurant/Cargo.toml b/restaurant/Cargo.toml new file mode 100644 index 0000000..7ed2828 --- /dev/null +++ b/restaurant/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "restaurant" +version = "0.1.0" +authors = ["Jordan Gong <jordan.gong@protonmail.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/restaurant/src/lib.rs b/restaurant/src/lib.rs new file mode 100644 index 0000000..eaab79f --- /dev/null +++ b/restaurant/src/lib.rs @@ -0,0 +1,77 @@ +mod front_of_house { + pub mod hosting { + pub fn add_to_waitlist() {} + + fn seat_at_table() {} + } + + mod serving { + fn take_order() {} + + fn serve_order() {} + + fn take_payment() {} + } +} + +fn serve_order() {} + +mod back_of_house { + fn fix_incorrect_order() { + cook_order(); + super::serve_order(); + } + + fn cook_order() {} + + pub struct Breakfast { + pub toast: String, + seasonal_fruit: String, + } + + impl Breakfast { + pub fn summer(toast: &str) -> Breakfast { + Breakfast { + toast: String::from(toast), + seasonal_fruit: String::from("peach"), + } + } + } + + pub enum Appetizer { + Soup, + Salad, + } +} + +pub fn eat_at_restaurant() { + // Absolute path + crate::front_of_house::hosting::add_to_waitlist(); + + // Relative path + front_of_house::hosting::add_to_waitlist(); + + let mut meal = back_of_house::Breakfast::summer("Rye"); + meal.toast = String::from("Wheat"); + println!("I'd like {} toast please", meal.toast); + + let order1 = back_of_house::Appetizer::Soup; + let order2 = back_of_house::Appetizer::Salad; + + { + use crate::front_of_house::hosting; + + hosting::add_to_waitlist(); + hosting::add_to_waitlist(); + hosting::add_to_waitlist(); + } + + { + use self::front_of_house::hosting; + + hosting::add_to_waitlist(); + hosting::add_to_waitlist(); + hosting::add_to_waitlist(); + } +} + diff --git a/restaurant/src/main.rs b/restaurant/src/main.rs new file mode 100644 index 0000000..11472db --- /dev/null +++ b/restaurant/src/main.rs @@ -0,0 +1,4 @@ +fn main() { + restaurant::eat_at_restaurant(); +} + |