Understanding Module Visibility in Rust
📖 Scenario: You are building a small Rust project that organizes code into modules. You want to control which parts of your code are visible outside their modules, just like how you might decide which rooms in a house are open to guests.
🎯 Goal: Learn how to use pub to make modules and functions visible outside their module, and how to keep some parts private.
📋 What You'll Learn
Create a module named
kitchen with a private functionCreate a module named
living_room with a public functionUse
pub keyword to control visibilityCall the public function from
living_room in mainTry to call the private function from
kitchen in main and observe the error💡 Why This Matters
🌍 Real World
In real Rust projects, controlling module visibility helps keep code clean and prevents accidental use of internal details.
💼 Career
Understanding module visibility is essential for writing maintainable Rust code in professional software development.
Progress0 / 4 steps