-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc(book): explain the schema importing mechanism
This section was still empty and despite even now being somewhat incomplete, at least provides some basic explanation of the importing system.
- Loading branch information
Showing
6 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
# Imports | ||
|
||
## Schema | ||
When splitting data structures into multiple Schema files, imports are used to reference the types defined within. Imports are declared with the `use` statement. | ||
|
||
<<< imports/basic.mabo | ||
These come in two flavors: | ||
|
||
- Import a specific type. | ||
|
||
<<< imports/struct.mabo | ||
|
||
- Import only a module. | ||
|
||
<<< imports/module.mabo | ||
|
||
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`. | ||
|
||
<<< imports/other.mabo | ||
|
||
When importing the above schema, we bring the `addresses` module into scope and can reference all the contained types: | ||
|
||
<<< imports/scoping.mabo |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use other::my_module; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
mod users { | ||
mod addresses { | ||
struct Street { | ||
name: string @1, | ||
house_no: string @2, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use other::users::addresses; | ||
|
||
struct MyStruct { | ||
street: addresses::Street @1, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use other::my_module::MyStruct; |