Modules and imports

A Dust program can be split in many modules. A (public) value defined in a different module can then be imported and used from other modules.

A module's namespace is equals to it's path (with regard to the project's source-directory folder - usually src):

For example, if the my-dust-project/src/A/B.ds file contains:

pub let x = 42;

Then we can use the import statements to make those values available:

A.B.x // unbound

import A.B;

A.B.x // => 42

Namespaces can be aliased:

import A.B as Z;

Z.x // => 42

Or make some or all the namespaces values available in the scope:

import A(x, y);
// `A.x`, `A.y`, `x` and `y` are in scope now

import A(..);
// every value inside `A` is in scope now

It's also possible to have scoped import expressions inside blocks:

{
  import A;
  A.x
}
// `A` namespace is not accessible here

⚠️ Scoped imports, and unqualified imports (such as import A(..) or import A(x, y)) are not implemented yet

Cheatsheet

Suppose there's a module with A namespace containing x and y.

Import commandWhat is brought into scope
import AA.x, A.y
import A(x)A.x, A.y, x
import A(..)A.x, A.y, x, y
import A as ZZ.x, Z.y
import A(x) as ZZ.x, Z.y, x
import A(..) as ZZ.x, Z.y, x, y