some more stuff
This commit is contained in:
parent
cc2f1b67a8
commit
eb9773627e
12 changed files with 150 additions and 0 deletions
7
ch7/restaurant/Cargo.lock
generated
Normal file
7
ch7/restaurant/Cargo.lock
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "restaurant"
|
||||
version = "0.1.0"
|
||||
6
ch7/restaurant/Cargo.toml
Normal file
6
ch7/restaurant/Cargo.toml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[package]
|
||||
name = "restaurant"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
2
ch7/restaurant/src/front_of_house.rs
Normal file
2
ch7/restaurant/src/front_of_house.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pub mod hosting;
|
||||
mod serving;
|
||||
2
ch7/restaurant/src/front_of_house/hosting.rs
Normal file
2
ch7/restaurant/src/front_of_house/hosting.rs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
pub fn add_to_waitlist() {}
|
||||
fn seat_at_table() {}
|
||||
3
ch7/restaurant/src/front_of_house/serving.rs
Normal file
3
ch7/restaurant/src/front_of_house/serving.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fn take_order() {}
|
||||
fn serve_order() {}
|
||||
fn take_payment() {}
|
||||
49
ch7/restaurant/src/lib.rs
Normal file
49
ch7/restaurant/src/lib.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
mod front_of_house;
|
||||
|
||||
mod back_of_house {
|
||||
// All fields are public or private along with the enum itself
|
||||
pub enum Appetizer {
|
||||
Soup,
|
||||
Salad,
|
||||
}
|
||||
|
||||
// Fields have to be marked pub as well to be used publicly
|
||||
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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn fix_incorrect_order() {
|
||||
cook_order();
|
||||
super::deliver_order(); // Child scope can access anything in parent
|
||||
}
|
||||
|
||||
fn cook_order() {}
|
||||
}
|
||||
|
||||
fn deliver_order() { }
|
||||
|
||||
// Note how the front_of_house mod is still private.
|
||||
// eat_at_restaurant can access its public children because it is
|
||||
// defined at the same scope.
|
||||
pub fn eat_at_restaurant() {
|
||||
// abs path
|
||||
crate::front_of_house::hosting::add_to_waitlist();
|
||||
|
||||
// rel path
|
||||
front_of_house::hosting::add_to_waitlist();
|
||||
|
||||
let mut meal = back_of_house::Breakfast::summer("Rye");
|
||||
meal.toast = String::from("Wheat");
|
||||
println!("id like {} toast please", meal.toast);
|
||||
// meal.seasonal_fruit = String::from("blackberries");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue