diff options
author | garhve <git@garhve.com> | 2022-12-30 13:47:02 +0800 |
---|---|---|
committer | garhve <git@garhve.com> | 2022-12-30 13:47:02 +0800 |
commit | 7fdb9249afe07c75ad8bea568195a3a8d979d73a (patch) | |
tree | 7360a15557b767071917204a1868b5672372dcb5 /rust/theBook/chapter-7-managing-growing-projects/restaurent | |
parent | 8a8302fa5d94425c01b358de57c071d32af6b7ed (diff) |
finish chapter 8
Diffstat (limited to 'rust/theBook/chapter-7-managing-growing-projects/restaurent')
-rw-r--r-- | rust/theBook/chapter-7-managing-growing-projects/restaurent/Cargo.toml | 8 | ||||
-rw-r--r-- | rust/theBook/chapter-7-managing-growing-projects/restaurent/src/lib.rs | 49 |
2 files changed, 57 insertions, 0 deletions
diff --git a/rust/theBook/chapter-7-managing-growing-projects/restaurent/Cargo.toml b/rust/theBook/chapter-7-managing-growing-projects/restaurent/Cargo.toml new file mode 100644 index 0000000..635e1ad --- /dev/null +++ b/rust/theBook/chapter-7-managing-growing-projects/restaurent/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "restaurent" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/rust/theBook/chapter-7-managing-growing-projects/restaurent/src/lib.rs b/rust/theBook/chapter-7-managing-growing-projects/restaurent/src/lib.rs new file mode 100644 index 0000000..6eb8cb5 --- /dev/null +++ b/rust/theBook/chapter-7-managing-growing-projects/restaurent/src/lib.rs @@ -0,0 +1,49 @@ +mod front_of_house { + pub mod hosting { + pub fn add_to_waitlist() {} + fn seat_at_table() {} + } + + mod serving { + fn take_order() {} + fn serve_order() {} + fn take_payment() {} + } +} + +fn deliver_order() {} + +mod back_of_house { + fn fix_incorrect_order() { + cook_order(); + super::deliver_order(); + } + + fn cook_order() {} + + pub struct Breakfast { + seasonal_fruits: String, + pub toast: String, + } + + impl Breakfast { + pub fn summer(toast: &str) -> Self { + Self { + toast: String::from(toast), + seasonal_fruits: String::from("Peach"), + } + } + } +} + +pub mod eat_at_restaurent { + // absolute +// crate::front_of_house::hosting::add_to_waitlist(); + + // relative +// front_of_house::hosting::add_to_waitlist(); + let mut meal = back_of_house::Breakfast::summer("Rye"); + + meal.toast = String::from("Wheat"); + println!("I'd like {} toast please.", meal.toast); +} |