Introduction
In this lab, we learn about the visibility of items in Rust modules, including the default private visibility, the use of the pub
modifier to override visibility, and the different levels of visibility such as pub(in path)
, pub(self)
, pub(super)
, and pub(crate)
. We also explore nested modules and the restrictions on accessing private items within modules.
Note: If the lab does not specify a file name, you can use any file name you want. For example, you can use main.rs
, compile and run it with rustc main.rs && ./main
.
Skills Graph
%%%%{init: {'theme':'neutral'}}%%%%
flowchart RL
rust(("`Rust`")) -.-> rust/DataTypesGroup(["`Data Types`"])
rust(("`Rust`")) -.-> rust/FunctionsandClosuresGroup(["`Functions and Closures`"])
rust(("`Rust`")) -.-> rust/DataStructuresandEnumsGroup(["`Data Structures and Enums`"])
rust/DataTypesGroup -.-> rust/type_casting("`Type Conversion and Casting`")
rust/FunctionsandClosuresGroup -.-> rust/function_syntax("`Function Syntax`")
rust/FunctionsandClosuresGroup -.-> rust/expressions_statements("`Expressions and Statements`")
rust/DataStructuresandEnumsGroup -.-> rust/method_syntax("`Method Syntax`")
subgraph Lab Skills
rust/type_casting -.-> lab-99332{{"`Rust Module Visibility Exploration`"}}
rust/function_syntax -.-> lab-99332{{"`Rust Module Visibility Exploration`"}}
rust/expressions_statements -.-> lab-99332{{"`Rust Module Visibility Exploration`"}}
rust/method_syntax -.-> lab-99332{{"`Rust Module Visibility Exploration`"}}
end