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 with
21//!   peephole optimization, constant folding, dead-code elimination, and
22//!   tail-call optimization
23//! - **`derive`** (default) — `#[derive(IonType)]` for host type injection
24//! - **`async-runtime`** — Native Tokio async evaluation via
25//!   [`engine::Engine::eval_async`], async host functions, `spawn`/`.await`/
26//!   `select`, timers, and channels
27//! - **`legacy-threaded-concurrency`** — Legacy sync-eval backend using OS
28//!   threads and crossbeam channels
29//! - **`msgpack`** — `Value::to_msgpack()` / `from_msgpack()` via `rmpv`
30//! - **`obfuscate`** — String obfuscation via `obfstr`
31//! - **`rewrite`** — Source rewriter at [`rewrite::replace_global`]
32
33/// Macro for string obfuscation. Returns a `String`.
34/// When the `obfuscate` feature is enabled, strings are encrypted at compile
35/// time and decrypted at runtime via `obfstr`. Without the feature, they
36/// pass through as regular `String`s.
37#[cfg(feature = "obfuscate")]
38macro_rules! ion_str {
39    ($s:literal) => {{
40        let _tmp: String = obfstr::obfstr!($s).to_string();
41        _tmp
42    }};
43}
44
45#[cfg(not(feature = "obfuscate"))]
46macro_rules! ion_str {
47    ($s:literal) => {
48        String::from($s)
49    };
50}
51
52/// Same as `ion_str!` but returns `&str` (non-obfuscated in obfuscate mode
53/// for contexts requiring `&'static str` like type_name()).
54/// These strings are short type names that are low-value for obfuscation.
55macro_rules! ion_static_str {
56    ($s:literal) => {
57        $s
58    };
59}
60
61pub mod ast;
62#[cfg(all(feature = "legacy-threaded-concurrency", not(feature = "async-runtime")))]
63pub mod async_rt;
64#[cfg(all(feature = "legacy-threaded-concurrency", not(feature = "async-runtime")))]
65pub mod async_rt_std;
66#[cfg(feature = "async-runtime")]
67pub mod async_runtime;
68#[cfg(feature = "vm")]
69pub mod bytecode;
70#[cfg(feature = "vm")]
71pub mod compiler;
72pub mod engine;
73pub mod env;
74pub mod error;
75pub mod host_types;
76pub mod intern;
77pub mod interpreter;
78pub mod lexer;
79pub mod module;
80pub mod parser;
81#[cfg(feature = "rewrite")]
82pub mod rewrite;
83pub mod stdlib;
84pub mod token;
85pub mod value;
86#[cfg(feature = "vm")]
87pub mod vm;
88
89pub use engine::Engine;
90pub use value::Value;
91
92#[cfg(feature = "derive")]
93pub use ion_derive::IonType;