Skip to content

Commit 2e35779

Browse files
committed
feat: add execise modules in diferent files/dirs
closes: #1143
1 parent 63e0fab commit 2e35779

File tree

8 files changed

+43
-0
lines changed

8 files changed

+43
-0
lines changed

dev/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ bin = [
8686
{ name = "modules2_sol", path = "../solutions/09_modules/modules2.rs" },
8787
{ name = "modules3", path = "../exercises/09_modules/modules3.rs" },
8888
{ name = "modules3_sol", path = "../solutions/09_modules/modules3.rs" },
89+
{ name = "modules4", path = "../exercises/09_modules/modules4.rs" },
90+
{ name = "modules4_sol", path = "../solutions/09_modules/modules4.rs" },
8991
{ name = "hashmaps1", path = "../exercises/11_hashmaps/hashmaps1.rs" },
9092
{ name = "hashmaps1_sol", path = "../solutions/11_hashmaps/hashmaps1.rs" },
9193
{ name = "hashmaps2", path = "../exercises/11_hashmaps/hashmaps2.rs" },

exercises/09_modules/cake.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
pub fn get_piece() {
4+
println!("Got cake piece!");
5+
}

exercises/09_modules/fruit/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn get_fav_fruit() {
2+
println("Got your favourite fruit!")
3+
}

exercises/09_modules/modules4.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//TODO: fix the compiler error for missing modules.
2+
3+
fn main() {
4+
cake::get_piece();
5+
fruit::get_fav_fruit();
6+
}

rustlings-macros/info.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,18 @@ hint = """
544544
`use` statement for these two to bring them into scope. You can use nested
545545
paths to bring these two in using only one line."""
546546

547+
[[exercises]]
548+
name = "modules4"
549+
dir = "09_modules"
550+
test = false
551+
hint = """
552+
The mod.rs is trying to use the modules from the file cake.rs and fruit directory.
553+
Complete the `mod` statements to fit the use in `main`.
554+
555+
Learn more in The Book:
556+
https://doc.rust-lang.org/book/ch07-05-separating-modules-into-different-files.html
557+
"""
558+
547559
# HASHMAPS
548560

549561
[[exercises]]

solutions/09_modules/cake.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
pub fn get_piece() {
4+
println!("Got cake piece!");
5+
}

solutions/09_modules/fruit/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn get_fav_fruit() {
2+
println("Got your favourite fruit!")
3+
}

solutions/09_modules/modules4.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
mod cake;
2+
mod fruit;
3+
4+
fn main() {
5+
cake::get_piece();
6+
fruit::get_fav_fruit();
7+
}

0 commit comments

Comments
 (0)