Optional Features

By default, Rhai includes all the standard functionalities in a small, tight package.

Most features are here to opt-out of certain functionalities that are not needed. Notice that this deviates from Rust norm where features are additive.

Excluding unneeded functionalities can result in smaller, faster builds as well as more control over what a script can (or cannot) do.

Features that Enable Special Functionalities

syncnorestricts all values types to those that are Send + Sync; under this feature, all Rhai types, including Engine, Scope and AST, are all Send + Sync
unicode-xid-identnoallows Unicode Standard Annex #31 as identifiers
serdeyesenables serialization/deserialization via serde (requires the serde crate)
metadatayesenables exporting functions metadata to JSON format (implies serde and additionally pulls in serde_json)
internalsyesexposes internal data structures (e.g. AST nodes); beware that Rhai internals are volatile and may change from version to version

Features that Disable Certain Language Features

no_floatnodisables floating-point numbers and math
no_indexnodisables arrays and indexing features
no_objectnodisables support for custom types and object maps
no_functionnodisables script-defined functions (implies no_closure)
no_modulenodisables loading external modules
no_closurenodisables capturing external variables in anonymous functions to simulate closures, or capturing the calling scope in function calls

Features that Disable Certain Engine Features

uncheckednodisables arithmetic checking (such as over-flows and division by zero), call stack depth limit, operations count limit and modules loading limit.
Beware that a bad script may panic the entire system!
no_optimizenodisables script optimization

Features that Configure the Engine

f32_floatnosets the system floating-point type to f32 instead of f64; FLOAT is set to f32
only_i32nosets the system integer type to i32 and disable all other integer types; INT is set to i32
only_i64nosets the system integer type to i64 and disable all other integer types; INT is set to i64

Features for no-std Builds

The following features are provided exclusively for no-std targets. Do not use them when not compiling for no-std.

no_stdnobuilds for no-std (implies no_closure); notice that additional dependencies will be pulled in to replace std features

Features for WebAssembly (WASM) Builds

The following features are provided exclusively for WASM targets. Do not use them for non-WASM targets.

wasm-bindgennouses wasm-bindgen to compile for WASM
stdwebnouses stdweb to compile for WASM


The Cargo.toml configuration below turns on these six features:

  • sync (everything Send + Sync)
  • unchecked (disable all checking – should not be used with untrusted user scripts)
  • only_i32 (only 32-bit signed integers)
  • no_float (no floating point numbers)
  • no_module (no loading external modules)
  • no_function (no defining functions)
rhai = { version = "{{version}}", features = [ "sync", "unchecked", "only_i32", "no_float", "no_module", "no_function" ] }

The resulting scripting engine supports only the i32 integer numeral type (and no others like u32, i16 or i64), no floating-point, is Send + Sync (so it can be safely used across threads), and does not support defining functions nor loading external modules.

This configuration is perfect for an expression parser in a 32-bit embedded system without floating-point hardware.

Caveat – Features Are Not Additive

Most Rhai features are not strictly additive – i.e. they do not only add optional functionalities.

In fact, most features are subtractive – i.e. they remove functionalities.

There is a reason for this design, because the lack of a language feature by itself is a feature.

See here for more details.