Skip to content
Kavachकवच

Modules

Also known as: import package namespace export public private visibility dependency project layout toml

● Intermediate5 minBefore this: Project LayoutSpec 10

One file is one module, a folder groups modules, and nothing leaves a module unless it is marked pub.

use billing.invoice

fn main() {
    const inv = invoice.create(7, 123)
    print("invoice {inv.id}: {inv.total}")
}

The program ran and printed:

kavach run

invoice 7: 130
src/main.kav and 1 more file: Kavach code, then what running it prints
  • src/billing/invoice.kav is the module billing.invoice: the path is the name, so you always know which file a name comes from.
  • use billing.invoice brings it in; then invoice.create(…) calls its pub function.
  • Everything is private until marked pub, fields included.

Private by default means you can change a module's inside freely: nothing outside can depend on what it doesn't make pub.

One page for each form