summaryrefslogtreecommitdiffstats
path: root/libs/restaurant
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libs/restaurant/Cargo.toml6
-rw-r--r--libs/restaurant/src/lib.rs57
2 files changed, 63 insertions, 0 deletions
diff --git a/libs/restaurant/Cargo.toml b/libs/restaurant/Cargo.toml
new file mode 100644
index 0000000..8e47b7a
--- /dev/null
+++ b/libs/restaurant/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "restaurant"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/libs/restaurant/src/lib.rs b/libs/restaurant/src/lib.rs
new file mode 100644
index 0000000..ca35d43
--- /dev/null
+++ b/libs/restaurant/src/lib.rs
@@ -0,0 +1,57 @@
+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);
+ }
+}