flâneur — a map of the web's best reading

Modules and crates - Rust for C-Programmers

rust-for-c-programmers.com · 476 words · saved by 1 readers

Modules encapsulate Rust source code, hiding internal implementation details. Crates are the fundamental units of code compilation and distribution in Rust. Modules provide namespaces and control the visibility of items (functions, structs, etc.). Items within a module are private by default and must be explicitly marked pub (public) to be accessible from outside the module. For larger projects, a module’s contents can be placed in a separate file instead of directly within its parent file. When you declare a module using mod my_module; in a file (e.g., main.rs or lib.rs), the compiler looks for the module’s code in one of two locations: Cargo handles the process of finding and compiling these files automatically based on the mod declarations. A crate is the smallest unit of compilation and distribution in Rust. There are two types: A Cargo project (package) can contain one library crate and/or multiple binary crates.

Explore this link on the map →

saved by