From 43ddbb814e679bf2adde3a8602624c207641dca2 Mon Sep 17 00:00:00 2001 From: hybrid Date: Wed, 14 Oct 2026 21:33:16 +0300 Subject: add: libs/restaurant, src/{hashmaps_01, piglatin} --- libs/restaurant/Cargo.toml | 6 +++++ libs/restaurant/src/lib.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 libs/restaurant/Cargo.toml create mode 100644 libs/restaurant/src/lib.rs (limited to 'libs') 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); + } +} -- cgit v1.3.1