Skip to content
Search

Rhai

lastmod 2025-09-20created 2025-09-201 edits

Embedded scripting language for Rust

About

  • Scripting language and execution engine that can be easily embedded in Rust applications
  • Designed to add dynamic logic through external scripts or to build custom DSLs
  • Highly compatible with Rust, with an architecture that considers performance, security, and extensibility
  • Runs on all Rust-supported platforms (WASM, no-std) with Rust 1.66.0+ or later
  • Syntax is a dynamically typed language similar to JavaScript + Rust
  • Performance: 0.14 seconds for 1 million iterations on a single-core 2.6GHz Linux VM
  • Native Rust integration: supports Rust functions, types, getters/setters, methods, and indexers
  • Rust values can be passed to scripts as variables/constants (using Scope)
  • Supports major data types: booleans, integers, floating point, Decimal, strings, Unicode characters, arrays, byte arrays, object maps
  • Functions defined in Rhai scripts can be called from Rust
  • Minimal dependencies (uses only a few libraries such as smallvec, thin-vec)
  • Re-entrant engine: Send + Sync possible via sync
  • Provides AST compilation and optimization
  • Supports a plugin system and macro-based API extension
  • Partial support for function/operator overloading, function pointers, currying, closures, and OOP patterns
  • Provides a module system; the codebase can be composed dynamically
  • serde serialization/deserialization support (optional)
  • Provides a debugging interface

Security and safety

  • Don’t Panic guarantee: a panic is considered a bug; the host system stays safe
  • Sandboxed execution: cannot change the external environment unless explicitly allowed
  • Protection against malicious attacks: blocks stack overflows, oversized data, and runaway execution
  • Execution progress can be tracked and terminated manually
  • Passes Miri checks

For those who want to build a custom language

  • Rhai can be used as a DSL
  • Specific language features such as loops can be disabled
  • Keywords/operators can be disabled and restricted
  • Custom operators and syntax extensions possible

Further resources

  • Project site: rhai.rs
  • Official documentation: The Rhai Book
  • Web-based Playground available (based on WebAssembly)

License

  • Choice of Apache 2.0 or MIT
  • Contributed code is dual-licensed by default

See also

Favorite site

author Zer0 sitemap