Files
mist-website/content/docs/guide/modules.mdx
T
2026-07-03 10:47:40 +02:00

34 lines
1.1 KiB
Plaintext

---
title: Modules & Imports
description: Module declarations, imports, re-exports, and module resolution rules.
icon: FolderTree
---
Mist's module system was created to fix Rust's dreaded parent-declared module system, files declare themselves and their publicity via `pub module my_mod;` as the first statement.
```mist
// Declare a module
pub module foo;
// Import
use std::collections::HashMap;
// Re-exporting import (alias)
pub use my_module::MyType;
```
### Module Resolution
Mist maps the module tree to Rust's module system:
| Mist Path | Rust Output |
|------------------------------|------------------------------|
| `src/main.mist` | `.mist/src/main.rs` |
| `src/utils/package.mist` | `.mist/src/utils/mod.rs` |
| `pub module foo;` | `.mist/src/foo.rs` |
A `package.mist` file acts as a directory's module root, analogous to `mod.rs`, but it's not required, as long as the directory contains `.mist` files, it will auto generate `mod.rs`.
#### *💡 Tip*: File names don't matter, `module my_mod` determines the name.