summaryrefslogtreecommitdiff
path: root/exercises/modules
diff options
context:
space:
mode:
Diffstat (limited to 'exercises/modules')
-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
4 files changed, 31 insertions, 3 deletions
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..87f0c45 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' statements 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 statements
+ 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!"),
+ }
+}