Home / Learn / 11 Packages and modules

Release v0.4.0Edition 0.2

11.8 Recap and reference

Page 9 of 9

11.8.1 For agents

A diagnostic about an import carries the place of the declaration as a related span, and its repair. For Private stays private:

json
{"schema":"una.diagnostics/1","diagnostics":[{"schema":"una.diagnostic/1","code":"U1004","severity":"error","domain":"names","message":"function `digits` is private to module `store.money`","primary":{"file":"src/store/app.una","start":{"line":4,"col":21},"end":{"line":4,"col":27}},"related":[{"file":"src/store/money.una","start":{"line":10,"col":1},"end":{"line":10,"col":7},"message":"declared here without `pub`"}],"repairs":[{"rank":1,"escape_cost":0,"widens":{"kind":"visibility","cost":"every module may then call it: check that it belongs to the module's interface"},"description":"declare `digits` with `pub`","edit":{"file":"src/store/money.una","start":{"line":10,"col":1},"end":{"line":10,"col":1},"replacement":"pub "}}],"explain":"una explain U1004"}],"fixable":0}

The repair has escape_cost 0, but widens names the visibility it would open, so una fix skips it. It gives the reason widens authority for every repair that widens what code may reach, visibility included:

Terminal
$ una fix --dry-run .
skipped src/store/money.una:10:1 U1004 declare `digits` with `pub`: widens authority

The compact rule: one module per file, named by its path; take each declaration you use with a named import; make a declaration pub only on purpose, with its whole header written; keep the imports free of cycles and sorted.

11.8.2 Recap

  • One file is one module, and its header names its path under src/: src/store/money.una is module store.money.
  • Declarations are private by default. Mark pub only what other modules need, with a doc comment and its whole header written.
  • Import each declaration you use by name. A sum kind brings its variants, and a record its constructor and fields.
  • Keep the imports a graph with no cycle, and let una fmt keep them sorted.
  • una.toml has a fixed set of tables and keys; an unknown one is U7002. A package imports only its own modules, std.host and std.testing.
  • verification.lock pins the solver, so every machine gets the same result: copy it, do not edit it.
  • Keep each module's examples in the module; una test . runs those of every module, after one check of the whole package.

11.8.3 Reference

Next:12 Capabilities