LogoMist

Modules & Imports

Module declarations, imports, re-exports, include directives, and module resolution rules.

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.

// Declare a module
pub module foo;

// Import
use std::collections::HashMap;

// Re-exporting import (alias)
pub use my_module::MyType;

Include Directives

Mist supports C-style include directives for

// Global include (std::Display)
// Includes all of the items *inside* the path
#include <std/fmt>

// Use include (std::Display)
// Includes *the path* itelf to the root.
#use std::fmt::Display;

// Local include
// Textual include, transpiles to rust include! macro via .rs extension
#include "my_local_module.mist"

Include directives allow you to bring in external code without using the module system, which is useful for C interop and local file organization.

Module Resolution

Mist maps the module tree to Rust's module system:

Mist PathRust 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.

On this page