diff --git a/restaurant/src/lib.rs b/restaurant/src/lib.rs index 1de805c..94db963 100644 --- a/restaurant/src/lib.rs +++ b/restaurant/src/lib.rs @@ -20,14 +20,85 @@ // mod front_of_house { - mod hosting { - fn add_to_waitlist() {} + 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 { + 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("peaches"), + } + } + } + + pub enum Appetizer { + Soup, + Salad, } + + fn fix_incorrect_order() { + cook_order(); + super::serve_order(); + } + + fn cook_order() {} +} + +// Either absolute: +// use crate::front_of_house::hosting; +// or relaive: +use front_of_house::hosting; +// we can also provide new names... +use crate::front_of_house::hosting as host; +// Public definitions braught into scope with use are +// private in this scope except we use «pub use» +pub use front_of_house::hosting as pubhost; + +pub fn eat_at_restaurant() { + // Absolute path + crate::front_of_house::hosting::add_to_waitlist(); + + // Relative path + front_of_house::hosting::add_to_waitlist(); + + // With use'd path + hosting::add_to_waitlist(); + + // With renamed used path + host::add_to_waitlist(); + + pubhost::add_to_waitlist(); + + // Order a breakfast in the summer with Rye toast + let mut meal = back_of_house::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 = back_of_house::Appetizer::Soup; + let order2 = back_of_house::Appetizer::Salad; }