Recall & Review
beginner
What is a module in Rust?
A module in Rust is a way to organize code into separate namespaces. It helps group related functions, structs, and other items together, making code easier to manage and understand.
Click to reveal answer
beginner
How do you define a module inside a Rust file?
You define a module using the
mod keyword followed by the module name and curly braces containing the module's code. For example: mod greetings { fn hello() { println!("Hi!"); } }Click to reveal answer
intermediate
What is the difference between
mod and use in Rust modules?mod defines a new module or declares it exists, while use brings items from a module into scope so you can use them without full paths.Click to reveal answer
beginner
How do you make a function inside a module accessible from outside the module?
You add the
pub keyword before the function to make it public. For example: pub fn greet() { println!("Hello!"); } Without pub, the function is private to the module.Click to reveal answer
intermediate
How can you split a module into multiple files in Rust?
You create a folder with the module name and add a
mod.rs file inside it, or in newer Rust versions, create a file named after the module. Then, submodules are files inside that folder. This helps organize large modules.Click to reveal answer
Which keyword is used to define a module in Rust?
✗ Incorrect
The
mod keyword defines a module in Rust.How do you make a function inside a module accessible from other modules?
✗ Incorrect
Functions are private by default. Adding
pub makes them accessible outside the module.What does the
use keyword do in Rust modules?✗ Incorrect
use brings items from a module into the current scope for easier access.If you define
mod greetings {} inside main.rs, where can you use the items inside greetings?✗ Incorrect
Public items inside a module can be used anywhere in the crate.
How can you organize a large module into multiple files?
✗ Incorrect
Large modules can be split into submodules placed in separate files or folders.
Explain how to define a module in Rust and make a function inside it accessible from outside.
Think about keywords to create modules and control access.
You got /3 concepts.
Describe how Rust modules help organize code and how you can split modules into multiple files.
Consider how big projects keep code tidy.
You got /4 concepts.