mod front_of_house; 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"), } } // just to test reading capabilities and resolve // "field never read" warning pub fn components(&self) { let v = vec![1, 2, 3, 4]; let does_not_exist = &v[100]; let does_not_exist = v.get(100); println!("toast: {}, seasonal fruit: {}", self.toast, self.seasonal_fruit) } } } pub fn add(left: u64, right: u64) -> u64 { left + right } pub fn eat_at_restaurant() { // 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); meal.components(); crate::front_of_house::hosting::add_to_waitlist(); // 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"); } #[cfg(test)] mod tests { use super::*; #[test] fn it_works() { let result = add(2, 2); assert_eq!(result, 4); } }