Modules (v0.2.1)

Imports, aliases, and selective import scopes.

Latest

Overview

Modules are brought into a file with import. A file can import a full module, give it an alias, or import only selected names.

Use selective imports when a file only needs a few symbols. This keeps the dependency list easier to scan.

Aliases are useful when a module path is long or repeated often.

Primary source: syntax/modules/import.md

Syntax Signatures

import std::io;
import std::collections::vector;
import "other.thrust" as dep;
import "other.thrust" only { stack, counter };

Behavior and Use

Imports should show what the file actually depends on. Avoid importing large modules when one or two names are enough.

Use a consistent import style across nearby files so readers do not have to adjust to a new pattern each time.

Best Practices

Import Forms

Imports control which external names are available in the current file.

Name Resolution

Qualified names make module boundaries explicit.

Example

import std::io;

fn main() s32 @public {
    io::print("module import works\n");
    return 0;
}

Back to language reference