ionlang-cli-0.1.0 is not a library.
Ion
A fast, embeddable scripting language for Rust applications.
Ion is designed for embedding in Rust programs — like Lua for game engines, but with Rust-flavored syntax and strong typing. It features a tree-walk interpreter and an optimizing bytecode VM, Serde-native host integration, and a rich standard library.
Quick Start
use Engine;
Features at a Glance
// Variables — immutable by default
let name = "Ion";
let mut counter = 0;
// Destructuring
let (x, y) = (10, 20);
let [head, ...rest] = [1, 2, 3, 4];
// String interpolation
let greeting = f"hello {name}!";
// Functions with default args
fn greet(who, greeting = "hello") {
f"{greeting}, {who}!"
}
// Pattern matching
let result = Ok(42);
match result {
Ok(n) if n > 0 => f"positive: {n}",
Ok(n) => f"non-positive: {n}",
Err(e) => f"error: {e}",
}
// First-class functions
let double = |x| x * 2;
[1, 2, 3].map(double) // [2, 4, 6]
// Dicts (JSON-like)
let config = #{
host: "localhost",
port: 8080,
tags: ["web", "api"],
};
// Error handling
fn parse(s) {
let n = s.to_int()?;
Ok(n * 2)
}
// Try/catch
try {
risky_operation();
} catch e {
f"caught: {e}"
}
// Modules and imports
use math::{add, PI};
let area = add(PI, PI);
// Loops + functional
let sum = [1, 2, 3, 4, 5].fold(0, |acc, x| acc + x);
for (i, item) in enumerate(items) {
io::println(f"{i}: {item}");
}
Embedding in Rust
use Engine;
use Value;
let mut engine = new;
// Register host functions
engine.register_fn;
// Use from Ion scripts
let result = engine.eval.unwrap;
assert_eq!;
Register Modules
use Module;
use Value;
let mut math = new;
math.register_fn;
math.set;
engine.register_module;
// Scripts can use: math::add(1, 2) or `use math::*;`
Host Types with Derive
use ;
use Value;
let mut engine = new;
engine.;
let result = engine.eval.unwrap;
Bytecode VM
let mut engine = new;
// Tree-walk interpreter (default)
let a = engine.eval.unwrap;
// Bytecode VM — faster for hot paths
let b = engine.vm_eval.unwrap;
assert_eq!;
Types
| Type | Example | Description |
|---|---|---|
| Int | 42, -1 |
64-bit signed integer |
| Float | 3.14 |
64-bit floating point |
| Bool | true, false |
Boolean |
| String | "hello", f"x={x}" |
UTF-8 string |
| List | [1, 2, 3] |
Ordered collection |
| Tuple | (1, "a", true) |
Fixed-size heterogeneous |
| Dict | #{key: val} |
Ordered key-value map |
| Option | Some(42), None |
Optional value |
| Result | Ok(val), Err(msg) |
Success or error |
| Bytes | b"\x00\xFF" |
Immutable byte array |
| Unit | () |
No value |
Project Structure
ion-core/ Core library — lexer, parser, interpreter, compiler, VM
ion-derive/ #[derive(IonType)] proc macro
ion-cli/ Script runner and REPL
ion-lsp/ Language server (VSCode support)
editors/ Editor syntax highlighting
Cargo Features
| Feature | Default | Description |
|---|---|---|
vm |
Yes | Bytecode compiler + stack VM |
optimize |
Yes | Peephole optimizer, constant folding, DCE, TCO |
derive |
Yes | #[derive(IonType)] proc macro |
concurrency |
No | Structured concurrency (spawn/await) |
obfuscate |
No | String obfuscation via obfstr |
Building
Language Reference
See LANGUAGE.md for the complete language specification.
License
MIT