Imports
When splitting data structures into multiple Schema files, imports are used to reference the types defined within. Imports are declared with the use
statement.
These come in two flavors:
Import a specific type.
mabouse other::my_module::MyStruct;
1Import only a module.
mabouse other::my_module;
1
Individual elements forming the import path are separated by a double-colon ::
. The first element is name of the external schema, and all intermediate elements are modules.
The last element is either omitted, which results in bringing the whole module into scope, or a specific type in that module or root schema.
Importing a module can help to reduce repetition if the module path is deep. Another use case is the avoidance of duplicate type names. For example:
Scoping example
A simple example with a somewhat deeply nested module structure, which we'll use in the next step. Let's consider this file to be named other.mabo
.
mod users {
mod addresses {
struct Street {
name: string @1,
house_no: string @2,
}
}
}
2
3
4
5
6
7
8
When importing the above schema, we bring the addresses
module into scope and can reference all the contained types:
use other::users::addresses;
struct MyStruct {
street: addresses::Street @1,
}
2
3
4
5