summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-06-22 13:24:06 +0200
committermo8it <mo8it@proton.me>2024-06-22 13:24:06 +0200
commit98cd00de6378550985d819ac8cd1227c8a10818e (patch)
treefe9d6d460813a043f7abbac7e063ce46c432b7af
parentecbe9b7324364e94f7c6b4a4dd279fb90f5a938e (diff)
modules2 solution
-rw-r--r--exercises/10_modules/modules2.rs19
-rw-r--r--rustlings-macros/info.toml11
-rw-r--r--solutions/10_modules/modules2.rs24
3 files changed, 38 insertions, 16 deletions
diff --git a/exercises/10_modules/modules2.rs b/exercises/10_modules/modules2.rs
index 5f8b0d5..24dce41 100644
--- a/exercises/10_modules/modules2.rs
+++ b/exercises/10_modules/modules2.rs
@@ -1,20 +1,19 @@
// You can bring module paths into scopes and provide new names for them with
-// the 'use' and 'as' keywords. Fix these 'use' statements to make the code
-// compile.
+// the `use` and `as` keywords.
mod delicious_snacks {
- // TODO: Fix these use statements
- use self::fruits::PEAR as ???
- use self::veggies::CUCUMBER as ???
+ // TODO: Add the follwing two `use` statements after fixing them.
+ // use self::fruits::PEAR as ???;
+ // use self::veggies::CUCUMBER as ???;
mod fruits {
- pub const PEAR: &'static str = "Pear";
- pub const APPLE: &'static str = "Apple";
+ pub const PEAR: &str = "Pear";
+ pub const APPLE: &str = "Apple";
}
mod veggies {
- pub const CUCUMBER: &'static str = "Cucumber";
- pub const CARROT: &'static str = "Carrot";
+ pub const CUCUMBER: &str = "Cucumber";
+ pub const CARROT: &str = "Carrot";
}
}
@@ -22,6 +21,6 @@ fn main() {
println!(
"favorite snacks: {} and {}",
delicious_snacks::fruit,
- delicious_snacks::veggie
+ delicious_snacks::veggie,
);
}
diff --git a/rustlings-macros/info.toml b/rustlings-macros/info.toml
index 97d7e07..ba414e3 100644
--- a/rustlings-macros/info.toml
+++ b/rustlings-macros/info.toml
@@ -535,12 +535,13 @@ name = "modules2"
dir = "10_modules"
test = false
hint = """
-The delicious_snacks module is trying to present an external interface that is
-different than its internal structure (the `fruits` and `veggies` modules and
-associated constants). Complete the `use` statements to fit the uses in main and
-find the one keyword missing for both constants.
+The `delicious_snacks` module is trying to present an external interface that
+is different than its internal structure (the `fruits` and `veggies` modules
+and associated constants). Complete the `use` statements to fit the uses in
+`main` and find the one keyword missing for both constants.
-Learn more at https://doc.rust-lang.org/book/ch07-04-bringing-paths-into-scope-with-the-use-keyword.html#re-exporting-names-with-pub-use"""
+Learn more in The Book:
+https://doc.rust-lang.org/book/ch07-04-bringing-paths-into-scope-with-the-use-keyword.html#re-exporting-names-with-pub-use"""
[[exercises]]
name = "modules3"
diff --git a/solutions/10_modules/modules2.rs b/solutions/10_modules/modules2.rs
index 4e18198..55c316d 100644
--- a/solutions/10_modules/modules2.rs
+++ b/solutions/10_modules/modules2.rs
@@ -1 +1,23 @@
-// Solutions will be available before the stable release. Thank you for testing the beta version 🥰
+mod delicious_snacks {
+ // Added `pub` and used the expected alias after `as`.
+ pub use self::fruits::PEAR as fruit;
+ pub use self::veggies::CUCUMBER as veggie;
+
+ mod fruits {
+ pub const PEAR: &str = "Pear";
+ pub const APPLE: &str = "Apple";
+ }
+
+ mod veggies {
+ pub const CUCUMBER: &str = "Cucumber";
+ pub const CARROT: &str = "Carrot";
+ }
+}
+
+fn main() {
+ println!(
+ "favorite snacks: {} and {}",
+ delicious_snacks::fruit,
+ delicious_snacks::veggie,
+ );
+}