Files
mist-website/content/docs/components/modules-imports.mdx
T

70 lines
1.8 KiB
Plaintext

---
title: Modules & Imports
description: Organizing code across files with module declarations and path-based imports.
icon: FolderTree
---
Mist organizes code through a file-system based module system with explicit path imports.
## The Module System
Each `.mist` file in `src/` corresponds to a module. and a `directory/package.mist` is a package like mod.rs, packages don't need `package.mist` to be functional, as long as a `.mist` file exists it will map it to pacakge_name::file_name.
## Imports
Use the `use` keyword with a path to bring items from other modules or external crates into scope.
```mist
use std::fs;
use std::process;
use std::path::Path;
use std::collections::HashMap;
// Import specific items
use my_module::Helper;
```
### Visibility
Items can be re-exported with a visibility modifier on the import:
```mist
pub use internal::format;
```
## Sidefiles
Any non-`.mist` file in `src/` (e.g., `.rs`, `.toml`, data files) is treated as a **sidefile** — it is copied directly into the output directory `.mist/src/` during transpilation. This allows you to keep Rust helper files or configuration alongside your Mist source.
```text
src/
├── main.mist
├── helper.rs # copied to .mist/src/helper.rs
└── config/
└── data.json # copied to .mist/src/config/data.json
```
## Project Structure
A typical Mist project looks like this:
```
my-project/
├── Cargo.toml
├── src/
│ ├── main.mist
│ ├── my_api/
│ │ ├── package.mist
│ │ ├── methods.mist
│ │ └── utils.mist
└── .mist/
└── src/
├── main.rs
└── my_api/
├── mod.rs
├── methods.rs
└── utils.rs
```
The `.mist/src/` directory contains the transpiled Rust output.