summaryrefslogtreecommitdiffstats
path: root/src/doc/book/listings/ch07-managing-growing-projects/listing-07-09
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc/book/listings/ch07-managing-growing-projects/listing-07-09')
-rw-r--r--src/doc/book/listings/ch07-managing-growing-projects/listing-07-09/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch07-managing-growing-projects/listing-07-09/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch07-managing-growing-projects/listing-07-09/src/lib.rs27
3 files changed, 39 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch07-managing-growing-projects/listing-07-09/Cargo.lock b/src/doc/book/listings/ch07-managing-growing-projects/listing-07-09/Cargo.lock
new file mode 100644
index 000000000..f25ab358f
--- /dev/null
+++ b/src/doc/book/listings/ch07-managing-growing-projects/listing-07-09/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "restaurant"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch07-managing-growing-projects/listing-07-09/Cargo.toml b/src/doc/book/listings/ch07-managing-growing-projects/listing-07-09/Cargo.toml
new file mode 100644
index 000000000..60cec7cb0
--- /dev/null
+++ b/src/doc/book/listings/ch07-managing-growing-projects/listing-07-09/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "restaurant"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch07-managing-growing-projects/listing-07-09/src/lib.rs b/src/doc/book/listings/ch07-managing-growing-projects/listing-07-09/src/lib.rs
new file mode 100644
index 000000000..92c4695d5
--- /dev/null
+++ b/src/doc/book/listings/ch07-managing-growing-projects/listing-07-09/src/lib.rs
@@ -0,0 +1,27 @@
+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 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);
+
+ // 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");
+}