Modules and imports

Modules and imports

A file is a module. A package groups modules under an entry file, lib.peko, and submodules resolve as siblings of it: std::io is io.peko next to the standard library's entry.

Import forms

import std::fs;                  // a module, used as fs::read_file(...)
import pekoui as ui;             // a whole package under an alias
import pekoui::env;              // one submodule directly
import { * } from core;          // bring a module's public items into scope
import c::core::hash as hashing; // a C module, aliased

An aliased package reaches its modules through the alias:

import pekoui as ui;

let application: ui::app::App = ui::app::from_bundle()

What is already imported

Some of the standard library is available without an import:

Module How it is used
std::core Bare. The base types and traits are always in scope.
std::collections Bare. Array and Map need no import.
std::runtime Through its prefix, as runtime::.
std::json Through its prefix, as json::.
std::xml Through its prefix, as xml::.
std::bundle Through its prefix, as bundle::.

Everything else needs an explicit import, including the rest of the standard library. pekoui is never auto-imported.

A module inside a package gets a smaller prelude: std::core and std::collections unpacked, plus std::bundle. It does not get json, xml, or runtime for free, which is why library code carries imports an application would not need.

Exporting

A package entry re-exports its submodules with export:

export app;
export webview;
export bridge;

That is what lets a consumer write import pekoui as ui and reach ui::app.

Visibility

Public is the default, so an item is importable without any modifier. [public] records that the exposure is deliberate:

[public] fn stringify(value: JsonValue) => string {
    // importable from other modules
}

That matters most in a library. A function nothing calls inside its own module looks unused, and the analyzer says so. In a library that is the normal case, because the callers are consumers the compiler never sees. [public] settles the warning and states the intent.

[private] is the one that actually restricts. See the modifiers page for the full list and how they combine.