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(..)orimport A(x, y)) are not implemented yet
Cheatsheet
Suppose there's a module with A namespace containing x and y.
| Import command | What is brought into scope |
|---|---|
import A | A.x, A.y |
import A(x) | A.x, A.y, x |
import A(..) | A.x, A.y, x, y |
import A as Z | Z.x, Z.y |
import A(x) as Z | Z.x, Z.y, x |
import A(..) as Z | Z.x, Z.y, x, y |