Skip to main content

ion_core/
lib.rs

1#![allow(clippy::result_large_err)]
2//! Ion — an embeddable scripting language for Rust.
3//!
4//! Ion is a small, strongly-typed scripting language inspired by Starlark,
5//! designed for embedding in Rust applications. It features a tree-walk
6//! interpreter and an optional bytecode VM for better performance.
7//!
8//! # Quick Start
9//!
10//! ```rust
11//! use ion_core::engine::Engine;
12//!
13//! let mut engine = Engine::new();
14//! let result = engine.eval("1 + 2").unwrap();
15//! assert_eq!(result, ion_core::value::Value::Int(3));
16//! ```
17//!
18//! # Features
19//!
20//! - **`vm`** (default) — Bytecode compiler and stack-based VM
21//! - **`optimize`** (default) — Peephole optimizer, constant folding,
22//!   dead-code elimination, tail-call optimization
23//! - **`derive`** (default) — `#[derive(IonType)]` for host type injection
24//! - **`concurrency`** — Structured concurrency: `async`/`spawn`/`.await`/
25//!   `select`/`channel`, cooperative cancellation, tokio-friendly
26//!   embedding via [`engine::Engine::register_closure`]
27//! - **`msgpack`** — `Value::to_msgpack()` / `from_msgpack()` via `rmpv`
28//! - **`obfuscate`** — String obfuscation via `obfstr`
29//! - **`rewrite`** — Source rewriter at [`rewrite::replace_global`]
30
31/// Macro for string obfuscation. Returns a `String`.
32/// When the `obfuscate` feature is enabled, strings are encrypted at compile
33/// time and decrypted at runtime via `obfstr`. Without the feature, they
34/// pass through as regular `String`s.
35#[cfg(feature = "obfuscate")]
36macro_rules! ion_str {
37    ($s:literal) => {{
38        let _tmp: String = obfstr::obfstr!($s).to_string();
39        _tmp
40    }};
41}
42
43#[cfg(not(feature = "obfuscate"))]
44macro_rules! ion_str {
45    ($s:literal) => {
46        String::from($s)
47    };
48}
49
50/// Same as `ion_str!` but returns `&str` (non-obfuscated in obfuscate mode
51/// for contexts requiring `&'static str` like type_name()).
52/// These strings are short type names that are low-value for obfuscation.
53macro_rules! ion_static_str {
54    ($s:literal) => {
55        $s
56    };
57}
58
59pub mod ast;
60#[cfg(feature = "concurrency")]
61pub mod async_rt;
62#[cfg(feature = "concurrency")]
63pub mod async_rt_std;
64#[cfg(feature = "vm")]
65pub mod bytecode;
66#[cfg(feature = "vm")]
67pub mod compiler;
68pub mod engine;
69pub mod env;
70pub mod error;
71pub mod host_types;
72pub mod intern;
73pub mod interpreter;
74pub mod lexer;
75pub mod module;
76pub mod parser;
77#[cfg(feature = "rewrite")]
78pub mod rewrite;
79pub mod stdlib;
80pub mod token;
81pub mod value;
82#[cfg(feature = "vm")]
83pub mod vm;
84
85pub use engine::Engine;
86pub use value::Value;
87
88#[cfg(feature = "derive")]
89pub use ion_derive::IonType;