mirror of
https://github.com/notohh/rustlings.git
synced 2024-11-21 21:42:23 -05:00
modules2 solution
This commit is contained in:
parent
ecbe9b7324
commit
98cd00de63
3 changed files with 38 additions and 16 deletions
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue