Rhai’s purpose is to provide a dynamic layer over Rust code, in the same spirit of zero cost abstractions.
It doesn’t attempt to be a new language. For example:
No classes. Well, Rust doesn’t either. On the other hand…
No traits… so it is also not Rust. Do your Rusty stuff in Rust.
No structures/records/tuples – define your types in Rust instead; Rhai can seamlessly work with any Rust type that implements
- No first-class functions – Code your functions in Rust instead, and register them with Rhai.
There is support for simple function pointers to allow runtime dispatch by function name.
No garbage collection – this should be expected, so…
No first-class closures – do your closure magic in Rust instead: turn a Rhai scripted function into a Rust closure.
- No formal language grammar – Rhai uses a hand-coded lexer, a hand-coded top-down recursive-descent parser for statements, and a hand-coded Pratt parser for expressions.
This lack of formalism allows the tokenizer and parser themselves to be exposed as services in order to support a wide range of user customizations, such as:
- No byte-codes/JIT – Rhai uses a heavily-optimized AST-walking interpreter which is fast enough for most real-life scenarios.
See Rhai performance benchmarks.