File tree Expand file tree Collapse file tree 6 files changed +45
-9
lines changed Expand file tree Collapse file tree 6 files changed +45
-9
lines changed Original file line number Diff line number Diff line change 9
9
| primitive_types | §4.3 |
10
10
| structs | §5.1 |
11
11
| enums | §6 |
12
- | modules | §7.2 |
12
+ | modules | §7 |
13
13
| collections | §8.1, §8.3 |
14
14
| strings | §8.2 |
15
15
| 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.
4
4
5
5
## Further information
6
6
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 4
4
// I AM NOT DONE
5
5
6
6
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
+
7
12
fn make_sausage ( ) {
13
+ get_secret_recipe ( ) ;
8
14
println ! ( "sausage!" ) ;
9
15
}
10
16
}
Original file line number Diff line number Diff line change 1
1
// 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.
2
4
// Make me compile! Execute `rustlings hint modules2` for hints :)
3
5
4
6
// I AM NOT DONE
5
7
6
8
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 ???
9
13
10
14
mod fruits {
11
15
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"
362
362
path = " exercises/modules/modules2.rs"
363
363
mode = " compile"
364
364
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."""
370
378
371
379
# COLLECTIONS
372
380
You can’t perform that action at this time.
0 commit comments