summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoranuk909 <34924662+anuk909@users.noreply.github.com>2021-09-03 11:41:12 +0300
committerGitHub <noreply@github.com>2021-09-03 10:41:12 +0200
commitdfd2fab4f33d1bf59e2e5ee03123c0c9a67a9481 (patch)
tree2a0ec7ff07f4e77da0968afa88ed280e654ea97b
parent96fc3017642b1b4b224390320111c6e305c736a3 (diff)
feat(modules): update exercises, add modules3 (#822)
Co-authored-by: diannasoriel <mokou@fastmail.com>
-rw-r--r--exercises/README.md2
-rw-r--r--exercises/modules/README.md2
-rw-r--r--exercises/modules/modules1.rs6
-rw-r--r--exercises/modules/modules2.rs8
-rw-r--r--exercises/modules/modules3.rs18
-rw-r--r--info.toml18
6 files changed, 45 insertions, 9 deletions
diff --git a/exercises/README.md b/exercises/README.md
index eebbd0b..73754db 100644
--- a/exercises/README.md
+++ b/exercises/README.md
@@ -9,7 +9,7 @@
| primitive_types | §4.3 |
| structs | §5.1 |
| enums | §6 |
-| modules | §7.2 |
+| modules | §7 |
| collections | §8.1, §8.3 |
| strings | §8.2 |
| error_handling | §9 |
diff --git a/exercises/modules/README.md b/exercises/modules/README.md
index 6582b00..3dc8a48 100644
--- a/exercises/modules/README.md
+++ b/exercises/modules/README.md
@@ -4,4 +4,4 @@ In this section we'll give you an introduction to Rust's module system.
## Further information
-- [The Module System](https://doc.rust-lang.org/book/ch07-02-defining-modules-to-control-scope-and-privacy.html)
+- [The Module System](https://doc.rust-lang.org/book/ch07-00-managing-growing-projects-with-packages-crates-and-modules.html)
diff --git a/exercises/modules/modules1.rs b/exercises/modules/modules1.rs
index 812dfee..1a2bd0d 100644
--- a/exercises/modules/modules1.rs
+++ b/exercises/modules/modules1.rs
@@ -4,7 +4,13 @@
// I AM NOT DONE
mod sausage_factory {
+ // Don't let anybody outside of this module see this!
+ fn get_secret_recipe() -> String {
+ String::from("Ginger")
+ }
+
fn make_sausage() {
+ get_secret_recipe();
println!("sausage!");
}
}
diff --git a/exercises/modules/modules2.rs b/exercises/modules/modules2.rs
index fde439d..687bb78 100644
--- a/exercises/modules/modules2.rs
+++ b/exercises/modules/modules2.rs
@@ -1,11 +1,15 @@
// modules2.rs
+// You can bring module paths into scopes and provide new names for them with the
+// 'use' and 'as' keywords. Fix these 'use' statments to make the code compile.
// Make me compile! Execute `rustlings hint modules2` for hints :)
// I AM NOT DONE
mod delicious_snacks {
- use self::fruits::PEAR as fruit;
- use self::veggies::CUCUMBER as veggie;
+
+ // TODO: Fix these use statments
+ use self::fruits::PEAR as ???
+ use self::veggies::CUCUMBER as ???
mod fruits {
pub const PEAR: &'static str = "Pear";
diff --git a/exercises/modules/modules3.rs b/exercises/modules/modules3.rs
new file mode 100644
index 0000000..8eed77d
--- /dev/null
+++ b/exercises/modules/modules3.rs
@@ -0,0 +1,18 @@
+// modules3.rs
+// You can use the 'use' keyword to bring module paths from modules from anywhere
+// and especially from the Rust standard library into your scope.
+// Bring SystemTime and UNIX_EPOCH
+// from the std::time module. Bonus style points if you can do it with one line!
+// Make me compile! Execute `rustlings hint modules3` for hints :)
+
+// I AM NOT DONE
+
+// TODO: Complete this use statement
+use ???
+
+fn main() {
+ match SystemTime::now().duration_since(UNIX_EPOCH) {
+ Ok(n) => println!("1970-01-01 00:00:00 UTC was {} seconds ago!", n.as_secs()),
+ Err(_) => panic!("SystemTime before UNIX EPOCH!"),
+ }
+}
diff --git a/info.toml b/info.toml
index d5008ed..0f68d05 100644
--- a/info.toml
+++ b/info.toml
@@ -362,11 +362,19 @@ name = "modules2"
path = "exercises/modules/modules2.rs"
mode = "compile"
hint = """
-The delicious_snacks module is trying to present an external
-interface (the `fruit` and `veggie` constants) that is different than
-its internal structure (the `fruits` and `veggies` modules and
-associated constants). It's almost there except for one keyword missing for
-each constant."""
+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` statemants to fit the uses in main and
+find the one keyword missing for both constants."""
+
+[[exercises]]
+name = "modules3"
+path = "exercises/modules/modules3.rs"
+mode = "compile"
+hint = """
+UNIX_EPOCH and SystemTime are declared in the std::time module. Add a use statement
+for these two to bring them into scope. You can use nested paths or the glob
+operator to bring these two in using only one line."""
# COLLECTIONS