add module3 exercise that shows uses of modules from std

This commit is contained in:
Shmulik Cohen 2021-08-13 14:03:09 +03:00
parent a09a2173ae
commit b87a2323ae
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,17 @@
// modules3.rs
// You can use the 'use' keyword to bring module paths from modules from anywere
// and espically from the rust standard library. 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!"),
}
}

View File

@ -368,6 +368,16 @@ its internal structure (the `fruits` and `veggies` modules and
associated constants). It's almost there except for one keyword missing for
each constant."""
[[exercises]]
name = "modules3"
path = "exercises/modules/modules3.rs"
mode = "compile"
hint = """
UNIX_EPOCH and SystemTime 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 one line
"""
# COLLECTIONS
[[exercises]]