Skip to main content

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.reportsWhat it is
radar::sensorsthe package — names joined by ::
trackinga level above the module; there may be any number of these, or none
reportsthe module — this file, the way a filename names a file
  • The :: separators are optional, so a single-name package is a header like module 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.tracking may declare tracking.

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, expected

A declaration above the header​

const max_range_m: int32 = 40000;   // error: expected
module radar::sensors.tracking      // error: unexpected

Two 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-module

Two declarations with one name​

const max_range_m: int32 = 40000;
const max_range_m: int32 = 50000;   // error: duplicate-declaration-name