Use the `pub` keyword to make Rust modules, structs, and functions accessible from outside their current scope.
Use the pub keyword to make items like modules, structs, and functions accessible from outside their current scope. By default, items are private to their module; adding pub exposes them to parent modules and other crates.
pub mod config {
pub fn load() -> String {
"settings".to_string()
}
}
fn main() {
let s = config::load();
}
The pub keyword acts like a public door for your code, allowing other parts of your program to see and use it. Without it, your functions and data are locked inside their own room and cannot be accessed from the outside. You use it whenever you want to share a tool or piece of data with the rest of your application.