module
A file header naming the file. That name is mandatory and unique across the project, it is the
namespace holding the file's declarations, and another file's import reaches them through it.
module radar::sensors.tracking
message struct TrackReport {
track_id: uint32;
bearing_deg: float32;
}Headers
A header is module and then the file's full name: a package, a ., then the module and any levels
above it, separated by ..
In module radar::sensors.tracking.reports | What it is |
|---|---|
radar::sensors | the package — names joined by :: |
tracking | a level above the module; there may be any number of these, or none |
reports | the module — this file, the way a filename names a file |
- The
::separators are optional, so a single-name package is a header likemodule tracking.reports. - The
.after the package is not optional. - A file carries exactly one header.
- The full name is unique across the project.
- A declaration's name is unique within the module.
- The file's name on disk need not match any part of it.
- The names in the header bind nothing inside the file, so a declaration may reuse one — a file headed
module radar::sensors.trackingmay declaretracking.
File shape
A file is its header, then its imports, then its global declarations. Only whitespace and comments may precede the header.
Errors
A header that stops at the package
The . and the name after it are part of the header, so a package on its own is not one.
module radar::sensors // error: expected, expectedA declaration above the header
const max_range_m: int32 = 40000; // error: expected
module radar::sensors.tracking // error: unexpectedTwo files naming the same module
Both files are reported, because neither is the one that is wrong.
module radar::sensors.tracking // error: duplicate-module
// ────────────────────────────
module radar::sensors.tracking // error: duplicate-moduleTwo declarations with one name
const max_range_m: int32 = 40000;
const max_range_m: int32 = 50000; // error: duplicate-declaration-nameRelated
- import — what may follow the header, and how another module's declarations get in.
- identifiers — what the names in a header may be.
- comments and whitespace — what may precede the header.