A. secret function is private and cannot be called from main
B. Missing semicolon after println!
C. Module my_mod is not declared public
D. Function secret must have pub keyword inside main
Solution
Step 1: Check function visibility
The function secret is not marked pub, so it is private to my_mod.
Step 2: Understand call from main
Since main is outside my_mod, it cannot call a private function, causing a compile error.
Final Answer:
secret function is private and cannot be called from main -> Option A
Quick Check:
Private functions can't be accessed outside module [OK]
Hint: Private functions can't be called outside their module [OK]
Common Mistakes:
Thinking module must be pub to call function
Assuming missing semicolon causes error
Believing pub inside main is needed
5. You have a private struct Config inside a module, but want to allow other modules to create instances with limited access to its fields. Which visibility setup is correct?
hard
A. Make struct private and fields public
B. Make struct pub but keep fields private
C. Make both struct and fields private
D. Keep struct private and make fields pub
Solution
Step 1: Understand struct and field visibility
Making the struct pub allows other modules to create instances, but keeping fields private restricts direct access to internal data.
Step 2: Evaluate other approaches
Keeping the struct private (with or without pub fields) prevents other modules from constructing instances. Making everything private blocks access entirely.
Final Answer:
Make struct pub but keep fields private -> Option B