File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 |
Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 44// I AM NOT DONE
55
66mod 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}
Original file line number Diff line number Diff line change 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
68mod 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" ;
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change @@ -362,11 +362,19 @@ name = "modules2"
362362path = " exercises/modules/modules2.rs"
363363mode = " compile"
364364hint = """
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
You can’t perform that action at this time.
0 commit comments