diff --git a/dev/Cargo.toml b/dev/Cargo.toml index 2d04379d..2f4c83d3 100644 --- a/dev/Cargo.toml +++ b/dev/Cargo.toml @@ -86,6 +86,8 @@ bin = [ { name = "modules2_sol", path = "../solutions/09_modules/modules2.rs" }, { name = "modules3", path = "../exercises/09_modules/modules3.rs" }, { name = "modules3_sol", path = "../solutions/09_modules/modules3.rs" }, + { name = "modules4", path = "../exercises/09_modules/modules4.rs" }, + { name = "modules4_sol", path = "../solutions/09_modules/modules4.rs" }, { name = "hashmaps1", path = "../exercises/11_hashmaps/hashmaps1.rs" }, { name = "hashmaps1_sol", path = "../solutions/11_hashmaps/hashmaps1.rs" }, { name = "hashmaps2", path = "../exercises/11_hashmaps/hashmaps2.rs" }, diff --git a/exercises/09_modules/fruit.rs b/exercises/09_modules/fruit.rs new file mode 100644 index 00000000..dceae23c --- /dev/null +++ b/exercises/09_modules/fruit.rs @@ -0,0 +1,3 @@ +pub fn get_fav_fruit() { + println("Got your favourite fruit!") +} diff --git a/exercises/09_modules/modules4.rs b/exercises/09_modules/modules4.rs new file mode 100644 index 00000000..12720e80 --- /dev/null +++ b/exercises/09_modules/modules4.rs @@ -0,0 +1,5 @@ +// TODO: fix the compiler error for missing modules. + +fn main() { + fruit::get_fav_fruit(); +} diff --git a/rustlings-macros/info.toml b/rustlings-macros/info.toml index 6b013b55..261c72f7 100644 --- a/rustlings-macros/info.toml +++ b/rustlings-macros/info.toml @@ -544,6 +544,18 @@ hint = """ `use` statement for these two to bring them into scope. You can use nested paths to bring these two in using only one line.""" +[[exercises]] +name = "modules4" +dir = "09_modules" +test = false +hint = """ +The mod.rs is trying to use the modules from the file cake.rs and fruit directory. +Complete the `mod` statements to fit the use in `main`. + +Learn more in The Book: +https://doc.rust-lang.org/book/ch07-05-separating-modules-into-different-files.html +""" + # HASHMAPS [[exercises]] diff --git a/solutions/09_modules/fruit.rs b/solutions/09_modules/fruit.rs new file mode 100644 index 00000000..dceae23c --- /dev/null +++ b/solutions/09_modules/fruit.rs @@ -0,0 +1,3 @@ +pub fn get_fav_fruit() { + println("Got your favourite fruit!") +} diff --git a/solutions/09_modules/modules4.rs b/solutions/09_modules/modules4.rs new file mode 100644 index 00000000..b5b77fca --- /dev/null +++ b/solutions/09_modules/modules4.rs @@ -0,0 +1,5 @@ +mod fruit; + +fn main() { + fruit::get_fav_fruit(); +}