Curriculum Errors, crates & tests Modules and visibility
Modules and visibility
Rust modules are not files by accident; they are the visibility and namespace system. This theme covers mod, use, pub, pub(crate), and paths with crate:: and super::. Planned exercises: 1. choose mod syntax. 2. recognise private-by-default items. 3. choose pub for exported APIs. 4. fill a use path. 5. fill pub(crate). 6. write a small module API. 7. write imports from sibling modules. 8. translate TS exports/imports. 9. fix a private-field or private-item compile error.
Exercises
9 ready
01
pick one
Declare an INLINE module called math containing one
02
pick one
rustc rejects the program below with `error[E0603]: function
03
pick one
Inside a module, you want a function callable from OUTSIDE
04
fill blanks
Fill the item name in the use path so math::add is
05
fill blanks
Fill the visibility modifier that exposes an item WITHIN the
06
write a program
Define an INLINE module math exposing one PUBLIC function
07
write a program
Two sibling inline modules in one file: math exposes
08
write a program
Translate the TS export class Counter pattern. Inline
09
write a program
This program fails with error[E0616]: field count` of struct