Features of Rhai
-
Simple language similar to JavaScript+Rust with dynamic typing.
-
Tight integration with native Rust functions and types including getters/setters, methods and indexers.
-
Freely pass Rust values into a script as variables/constants via an external
Scope
– all clonable Rust types are supported seamlessly without the need to implement any special trait. -
Easily call a script-defined function from Rust.
-
Very few additional dependencies – right now only
smallvec
,thin-vec
,num-traits
,ahash
,bitflags
andsmartstring
; forno-std
and WASM builds, a number of additional dependencies are pulled in to provide for missing functionalities. -
Plugins system powered by procedural macros simplifies custom API development.
-
Fairly efficient evaluation – 1 million iterations in 0.14 sec on a single-core, 2.6 GHz Linux VM (see benchmarks).
-
Compile once to AST for repeated evaluations.
-
Scripts are optimized – useful for template-based machine-generated scripts.
-
Organize code base with dynamically-loadable modules, optionally overriding the resolution process.
-
Dynamic dispatch via function pointers with additional support for currying.
-
Closures that can capture shared variables.
-
Some support for object-oriented programming (OOP).
-
Hook into variables access via a variable resolver, or control definition of variables via a variable definition filter.
-
Relatively little
unsafe
code – yes there are some for performance reasons. -
Sand-boxed – the scripting
Engine
, if declared immutable, cannot mutate the containing environment unless explicitly permitted. -
Passes Miri.
-
Don’t Panic guarantee – Any panic is a bug. It never panics the host system.
-
Protected against malicious attacks – such as stack-overflow, over-sized data, and runaway scripts etc. – that may come from untrusted third-party user-land scripts.
-
Track script evaluation progress and manually terminate a script run.
-
Re-entrant scripting
Engine
can be madeSend + Sync
(via thesync
feature). -
Support for
Decimal
numbers. -
Serialization/deserialization support via
serde
. -
Support for minimal builds by excluding unneeded language features.
-
Supports most build targets including
no-std
and WASM. -
Surgically disable keywords and operators to restrict the language.
-
Use as a DSL by defining custom operators and/or extending the language with custom syntax.
-
A debugging interface provides powerful debugging support.