A. Function hammer is private and cannot be accessed outside the module
B. Module tools is not declared correctly
C. Missing semicolon after println!
D. Cannot call functions inside modules
Solution
Step 1: Check function visibility
The function hammer is not marked pub, so it is private to the module.
Step 2: Understand access rules
Trying to call tools::hammer() from main causes an error because the function is private.
Final Answer:
Function hammer is private and cannot be accessed outside the module -> Option A
Quick Check:
Private function access error = A [OK]
Hint: Mark functions 'pub' to access outside modules [OK]
Common Mistakes:
Assuming all module functions are public by default
Thinking module declaration is wrong
Missing semicolon in println! (actually correct here)
5. You want to organize a Rust project with two modules: math and utils. The math module has a public function add that you want to use in utils. How should you structure the code to allow utils to call math::add?
hard
A. Make add private and call it directly from utils
B. Modules cannot call functions from each other
C. Define add inside utils instead of math
D. Declare both modules in the root, mark add as pub, and use use crate::math::add; inside utils
Solution
Step 1: Make function public
The add function must be marked pub to be accessible outside math.
Step 2: Use 'use' to import function
Inside utils, use use crate::math::add; to bring add into scope for calling.
Final Answer:
Declare both modules in the root, mark add as pub, and use use crate::math::add; inside utils -> Option D
Quick Check:
Public function + use import = B [OK]
Hint: Make functions pub and import with use to share between modules [OK]
Common Mistakes:
Leaving function private and expecting access
Trying to call private functions directly
Thinking modules cannot share code
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.