diff --git a/restaurant/Cargo.toml b/restaurant/Cargo.toml new file mode 100644 index 0000000..1488b4d --- /dev/null +++ b/restaurant/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "restaurant" +version = "0.1.0" +authors = ["laurens "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/restaurant/src/back_of_house.rs b/restaurant/src/back_of_house.rs new file mode 100644 index 0000000..d20406e --- /dev/null +++ b/restaurant/src/back_of_house.rs @@ -0,0 +1 @@ +pub mod cooking; diff --git a/restaurant/src/back_of_house/cooking.rs b/restaurant/src/back_of_house/cooking.rs new file mode 100644 index 0000000..0d3b401 --- /dev/null +++ b/restaurant/src/back_of_house/cooking.rs @@ -0,0 +1,28 @@ +pub struct Breakfast { // Struct is public but its members aren't! + pub toast: String, // Customer can choose which toast he wants + seasonal_fruit: String, // Only chef can choose fruit that is served +} + +pub enum Appetizer { // Enum is public and its possible variants too! + Soup, + Salad, +} + +fn do_nothing() {} + +fn fix_incorrect_order() { + cook_order(); + + crate::serve_order(); +} + +fn cook_order() {} + +impl Breakfast { + pub fn summer(toast: &str) -> Breakfast { + Breakfast { + toast: String::from(toast), + seasonal_fruit: String::from("peaches"), + } + } +} diff --git a/restaurant/src/front_of_house.rs b/restaurant/src/front_of_house.rs new file mode 100644 index 0000000..d0a8154 --- /dev/null +++ b/restaurant/src/front_of_house.rs @@ -0,0 +1 @@ +pub mod hosting; diff --git a/restaurant/src/front_of_house/hosting.rs b/restaurant/src/front_of_house/hosting.rs new file mode 100644 index 0000000..d65f3af --- /dev/null +++ b/restaurant/src/front_of_house/hosting.rs @@ -0,0 +1 @@ +pub fn add_to_waitlist() {} diff --git a/restaurant/src/lib.rs b/restaurant/src/lib.rs new file mode 100644 index 0000000..72dfdd1 --- /dev/null +++ b/restaurant/src/lib.rs @@ -0,0 +1,42 @@ +use std::collections::*; +use std::{self, cmp::Ordering, io}; + +mod front_of_house; + +pub use crate::front_of_house::hosting; +// pub use front_of_house::hosting; + +mod back_of_house; + +use crate::back_of_house::cooking::Breakfast as boh_breakfast; +use back_of_house::cooking; + +mod util; + +pub fn eat_at_restaurant() { + // // Absolute path + crate::front_of_house::hosting::add_to_waitlist(); + + // // Relative path + front_of_house::hosting::add_to_waitlist(); + + // // Making use of the 'use' keyword + hosting::add_to_waitlist(); + + // Order a breakfast in the summer with Rye toast + let mut meal = boh_breakfast::summer("Rye"); + // Change our mind about what bread we'd like + meal.toast = String::from("Wheat"); + println!("I'd like {} toast please", meal.toast); + + // The next line won't compile if we uncomment it; we're not allowed + // to see or modify the seasonal fruit that comes with the meal + // meal.seasonal_fruit = String::from("blueberries"); + + let order1 = cooking::Appetizer::Soup; + let order2 = cooking::Appetizer::Salad; + + util::get_cutlery(); +} + +fn serve_order() {} diff --git a/restaurant/src/util.rs b/restaurant/src/util.rs new file mode 100644 index 0000000..f1419b7 --- /dev/null +++ b/restaurant/src/util.rs @@ -0,0 +1 @@ +pub fn get_cutlery() {} \ No newline at end of file