You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Modules are a way to organize your code into separate files.
4
+
5
+
## File Structure
6
+
7
+
As long as you have a `main.rue` file in the root of your project, the compiler will automatically include all of the `.rue` files adjacent to it (including subdirectories) in the compilation.
8
+
9
+
All files are modules and can reference each other by name:
10
+
11
+
1. Each file includes every other adjacent file or directory in its scope.
12
+
2. Each directory's module automatically exports all of its children.
13
+
3. Each file has access to the parent directory's module with `super`.
14
+
15
+
If there is no `main.rue` file, then each file ending in `.rue` will be compiled completely independently, rather than as a single program.
16
+
17
+
## Paths
18
+
19
+
You can reference exported symbols and types from other modules by using the module name followed by the path to the symbol or type.
20
+
21
+
```rue
22
+
fn main() -> String {
23
+
utils::greet("Alice")
24
+
}
25
+
```
26
+
27
+
In this case, we are referencing the `greet` function from the `utils` module.
28
+
29
+
## Imports
30
+
31
+
Instead of referencing by path every time, you can import symbols and types from other modules into the current scope so that they can be referenced directly.
32
+
33
+
```rue
34
+
import utils::greet;
35
+
36
+
fn main() -> String {
37
+
greet("Alice")
38
+
}
39
+
```
40
+
41
+
You can import multiple paths:
42
+
43
+
```rue
44
+
import utils::{greet, exclaim};
45
+
46
+
fn main() -> String {
47
+
exclaim(greet("Alice"))
48
+
}
49
+
```
50
+
51
+
You can also import all symbols and types from a module by using the `*` wildcard:
52
+
53
+
```rue
54
+
import utils::*;
55
+
56
+
fn main() -> String {
57
+
exclaim(greet("Alice"))
58
+
}
59
+
```
60
+
61
+
Finally, it's possible to re-export things that you import:
62
+
63
+
```rue
64
+
export utils::*;
65
+
```
66
+
67
+
## Module Block
68
+
69
+
You can create a module by using the `mod` keyword followed by the name of the module. This is here for completeness more than anything, since most of the time you'll want to use multiple files instead.
0 commit comments