2.2 Program Structure
A Rust program typically consists of:
- Modules: Grouping related items (functions, structs, traits, etc.).
- Functions: Reusable units of code.
- Type Definitions: Structs, enums, type aliases.
- Constants and Statics: Immutable or fixed-location data.
use
Statements: Bringing external names into scope.
Unlike C, Rust does not require forward declarations for functions: you can freely call functions defined later in the file. This encourages a top-down design, where higher-level functions appear near the top, and detailed helpers below.
Important Exception: Variables must be declared before use.
Nesting: You can nest items in Rust where it makes sense (e.g., define helper functions or constants inside other functions or modules).