A crate is a compilation unit; modules organize code with mod, pub, and use. The playground is single-file, but real projects split into src/lib.rs and src/main.rs.
Module tree
mod front {
pub fn hello() { println!("hi"); }
}
Important interview questions and answers
- Q: Crate vs package?
A: Cargo package can contain multiple crates (lib + bin); crate is what rustc builds.
Self-check
- What keyword makes an item public?
- What does
usedo?