Skip to content

Commit dfd2fab

Browse files
anuk909manyinsects
andauthored
feat(modules): update exercises, add modules3 (#822)
Co-authored-by: diannasoriel <mokou@fastmail.com>
1 parent 96fc301 commit dfd2fab

File tree

6 files changed

+45
-9
lines changed

6 files changed

+45
-9
lines changed

exercises/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| primitive_types | §4.3 |
1010
| structs | §5.1 |
1111
| enums | §6 |
12-
| modules | §7.2 |
12+
| modules | §7 |
1313
| collections | §8.1, §8.3 |
1414
| strings | §8.2 |
1515
| error_handling | §9 |

exercises/modules/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ In this section we'll give you an introduction to Rust's module system.
44

55
## Further information
66

7-
- [The Module System](https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html)
7+
- [The Module System](https://doc.rust-lang.org/book/ch07-00-managing-growing-projects-with-packages-crates-and-modules.html)

exercises/modules/modules1.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
// I AM NOT DONE
55

66
mod sausage_factory {
7+
// Don't let anybody outside of this module see this!
8+
fn get_secret_recipe() -> String {
9+
String::from("Ginger")
10+
}
11+
712
fn make_sausage() {
13+
get_secret_recipe();
814
println!("sausage!");
915
}
1016
}

exercises/modules/modules2.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// modules2.rs
2+
// You can bring module paths into scopes and provide new names for them with the
3+
// 'use' and 'as' keywords. Fix these 'use' statments to make the code compile.
24
// Make me compile! Execute `rustlings hint modules2` for hints :)
35

46
// I AM NOT DONE
57

68
mod delicious_snacks {
7-
use self::fruits::PEAR as fruit;
8-
use self::veggies::CUCUMBER as veggie;
9+
10+
// TODO: Fix these use statments
11+
use self::fruits::PEAR as ???
12+
use self::veggies::CUCUMBER as ???
913

1014
mod fruits {
1115
pub const PEAR: &'static str = "Pear";

exercises/modules/modules3.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// modules3.rs
2+
// You can use the 'use' keyword to bring module paths from modules from anywhere
3+
// and especially from the Rust standard library into your scope.
4+
// Bring SystemTime and UNIX_EPOCH
5+
// from the std::time module. Bonus style points if you can do it with one line!
6+
// Make me compile! Execute `rustlings hint modules3` for hints :)
7+
8+
// I AM NOT DONE
9+
10+
// TODO: Complete this use statement
11+
use ???
12+
13+
fn main() {
14+
match SystemTime::now().duration_since(UNIX_EPOCH) {
15+
Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()),
16+
Err(_) => panic!("SystemTime before UNIX EPOCH!"),
17+
}
18+
}

info.toml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,19 @@ name = "modules2"
362362
path = "exercises/modules/modules2.rs"
363363
mode = "compile"
364364
hint = """
365-
The delicious_snacks module is trying to present an external
366-
interface (the `fruit` and `veggie` constants) that is different than
367-
its internal structure (the `fruits` and `veggies` modules and
368-
associated constants). It's almost there except for one keyword missing for
369-
each constant."""
365+
The delicious_snacks module is trying to present an external interface that is
366+
different than its internal structure (the `fruits` and `veggies` modules and
367+
associated constants). Complete the `use` statemants to fit the uses in main and
368+
find the one keyword missing for both constants."""
369+
370+
[[exercises]]
371+
name = "modules3"
372+
path = "exercises/modules/modules3.rs"
373+
mode = "compile"
374+
hint = """
375+
UNIX_EPOCH and SystemTime are declared in the std::time module. Add a use statement
376+
for these two to bring them into scope. You can use nested paths or the glob
377+
operator to bring these two in using only one line."""
370378

371379
# COLLECTIONS
372380

0 commit comments

Comments
 (0)