Recall & Review
beginner
What does the
pub keyword do in Rust modules?The
pub keyword makes a module, function, or item visible outside its current module, allowing other parts of the program to access it.Click to reveal answer
beginner
What is the default visibility of items inside a Rust module?
By default, items inside a Rust module are private and cannot be accessed from outside the module unless marked with
pub.Click to reveal answer
intermediate
How do you make a nested module visible outside its parent module?
You must mark both the nested module and its parent module as
pub to make the nested module accessible from outside.Click to reveal answer
intermediate
Explain the difference between
pub(crate) and pub in Rust module visibility.pub(crate) makes an item visible only within the current crate (project), while pub makes it visible everywhere, including other crates.Click to reveal answer
beginner
Can a private function inside a public module be accessed from outside the module?
No, private functions inside a public module remain inaccessible from outside. Only items marked
pub are accessible externally.Click to reveal answer
What keyword makes a Rust module accessible from other modules?
✗ Incorrect
The
pub keyword makes modules and items accessible from outside their current module.If a module is declared as
pub but a function inside it is not, can the function be accessed outside?✗ Incorrect
Functions are private by default and must be marked
pub to be accessible outside their module.What does
pub(crate) mean in Rust?✗ Incorrect
pub(crate) restricts visibility to the current crate (project).How do you make a nested module accessible outside its parent module?
✗ Incorrect
Both parent and nested modules must be
pub to be accessible externally.What is the default visibility of a Rust module item?
✗ Incorrect
By default, items are private and not accessible outside their module.
Explain how Rust controls access to modules and their contents using visibility keywords.
Think about how you protect your personal stuff in a room and decide who can enter.
You got /4 concepts.
Describe the steps to make a nested module and its functions accessible from outside the crate.
Visibility works like unlocking doors in a house to let guests in.
You got /3 concepts.