definetly did not vibe code 0.0.5-alpha0
This commit is contained in:
@@ -4,7 +4,7 @@ description: Defining execution blocks with C-style ergonomics and Rust-powered
|
||||
icon: SquareFunction
|
||||
---
|
||||
|
||||
Functions are the primary unit of execution in Mist. They prioritize a traditional declaration order, placing the return type before the identifier to ensure signatures remain easy to scan in complex systems.
|
||||
Functions are the primary unit of execution in Mist. They prioritize a traditional declaration order, placing the return type before the identifier.
|
||||
|
||||
## Basic Syntax
|
||||
|
||||
@@ -28,18 +28,15 @@ Functions are private to their module by default. The `pub` modifier exports the
|
||||
pub i32 get_version() {
|
||||
return 1;
|
||||
}
|
||||
```
|
||||
|
||||
You can also point to a specific point (super or crate, or a custom path):
|
||||
```mist
|
||||
pub(crate) i32 get_version() {
|
||||
return 1;
|
||||
pub(crate) i32 internal_use() {
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## Mutable Parameters
|
||||
|
||||
Parameters follow Rust’s ownership rules but use Mist’s local variable syntax. Use `mut` to allow a function to modify its local binding of a value.
|
||||
Use `mut` to allow a function to modify its local binding of a value.
|
||||
|
||||
```mist
|
||||
void update_score(i32 mut current_score, i32 bonus) {
|
||||
@@ -58,9 +55,23 @@ pub str'a* choose_longer<'a, T: Display>(str'a* s1, str'a* s2, T meta) {
|
||||
}
|
||||
```
|
||||
|
||||
## Closures
|
||||
|
||||
Closures are anonymous functions that can capture their environment. The return type before the pipe is optional — when omitted, the closure body uses curly braces:
|
||||
|
||||
```mist
|
||||
var add = |i32 a, i32 b| { a + b };
|
||||
|
||||
// With explicit return type
|
||||
Option<i32> |var v| { Some(v) }
|
||||
|
||||
// Without return type
|
||||
var greet = |str* name| { println!("Hello {}", name) };
|
||||
```
|
||||
|
||||
## Attributes & Metadata
|
||||
|
||||
Metadata is applied via the `#[attr]` syntax directly above the declaration for compiler hints or testing.
|
||||
Metadata is applied via the `#[attr]` syntax directly above the declaration.
|
||||
|
||||
```mist
|
||||
#[inline]
|
||||
@@ -71,6 +82,7 @@ pub bool is_active(u32 id) {
|
||||
|
||||
## Key Characteristics
|
||||
|
||||
* **Scannable Signatures:** Placing return types first allows for rapid identification of a function's output.
|
||||
* **Unified Abstraction:** Lifetimes and type constraints are declared in one location, reducing signature noise.
|
||||
* **Zero-Cost Mapping:** Every function maps directly to a Rust `fn`, maintaining performance and ecosystem compatibility.
|
||||
- **Scannable Signatures**: Return types first for rapid identification of a function's output.
|
||||
- **Unified Abstraction**: Lifetimes and type constraints are declared in one location.
|
||||
- **Closure Support**: Anonymous functions with optional return type annotations.
|
||||
- **Zero-Cost Mapping**: Every function maps directly to a Rust `fn`.
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
---
|
||||
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, similar to Rust but with a cleaner import syntax.
|
||||
|
||||
## The Module System
|
||||
|
||||
Each `.mist` file in `src/` corresponds to a module. The module tree mirrors the file hierarchy. Directories can be declared as submodules using `mod`.
|
||||
|
||||
### File-Based Modules
|
||||
|
||||
The file `src/main.mist` is the crate root. Other files are discovered through `mod` declarations or by name — no explicit declaration is needed when a file exists at a matching path.
|
||||
|
||||
### Declaring Submodules
|
||||
|
||||
```mist
|
||||
// src/main.mist
|
||||
mod network;
|
||||
mod database;
|
||||
```
|
||||
|
||||
## Imports
|
||||
|
||||
Use the `use` keyword with angle brackets 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
|
||||
│ ├── lib/
|
||||
│ │ ├── parser.mist
|
||||
│ │ └── helper.rs
|
||||
│ └── _header.rs
|
||||
└── .mist/
|
||||
└── src/
|
||||
├── main.rs # transpiled output
|
||||
├── lib/
|
||||
│ ├── parser.rs
|
||||
│ └── helper.rs
|
||||
└── _header.rs
|
||||
```
|
||||
|
||||
The `.mist/src/` directory contains the transpiled Rust output. `_header.rs` is a special file that provides IDE support for Rust Analyzer.
|
||||
@@ -57,4 +57,4 @@ pub struct Buffer<'a, T> {
|
||||
- **Type-First Declaration**: Fields use the `type name` order to match function parameters and variable declarations.
|
||||
- **Comma-Separated Members**: Fields are separated by commas, maintaining a clean and consistent delimiter style.
|
||||
- **Rust Compatibility**: Maps 1:1 to Rust structs, ensuring zero-cost abstraction and full ecosystem interoperability.
|
||||
- **Direct Visibility**: The `pub` keyword replaces `pub` for a more consistent modifier language across the codebase.
|
||||
- **Direct Visibility**: The `pub` modifier controls access at the struct and field level.
|
||||
|
||||
Reference in New Issue
Block a user