mod front_of_house; pub fn eat_at_restaurant() { // 绝对路径 crate::front_of_house::hosting::add_to_waitlist(); // 相对路径 front_of_house::hosting::add_to_waitlist(); } // super关键字 fn serve_order() {} mod back_of_house { fn fix_incorrent_order() { cook_order(); super::serve_order(); // 绝对路径 crate::serve_order(); } fn cook_order() {} } // pub struct mod back_of_house1 { 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("apples"), } } } } pub fn eat_at_restaurant1 () { let mut meal = back_of_house1::Breakfast::summer("Rye"); meal.toast = String::from("Wheat"); println!("I.d like {} toast please", meal.toast); // meal.seasonal_fruit = String::from("blueberries"); // 报错 私有属性不能访问 } // use关键字 use crate::back_of_house1::Breakfast; // 相对路径 // use back_of_house1::Breakfast; pub fn eat_at_restaurant2 () { let mut meal = Breakfast::summer("Rye"); meal.toast = String::from("Wheat"); println!("I.d like {} toast please", meal.toast); // meal.seasonal_fruit = String::from("blueberries"); // 报错 私有属性不能访问 } use std::fmt::Result; use std::io::Result as IoResult;