Rust Examples

A number of examples can be found in the examples directory:

arrays_and_structsshows how to register a custom Rust type and using arrays on it
custom_types_and_methodsshows how to register a custom Rust type and methods for it
hellosimple example that evaluates an expression and prints the result
reuse_scopeevaluates two pieces of code in separate runs, but using a common Scope
serdeexample to serialize and deserialize Rust types with serde (requires the serde feature)
simple_fnshows how to register a simple function
stringsshows different ways to register functions taking string arguments
threadingshows how to communication to an Engine running in a separate thread via an MPSC channel

Running Examples

Examples can be run with the following command:

cargo run --example {example_name}

no-std Samples

To illustrate no-std builds, a number of sample applications are available under the no_std directory:

no_std_testbare-bones test application that evaluates a Rhai expression and sets the result as the return valuesizewee_allocabort

cargo run cannot be used to run a no-std sample. It must first be built:

cd no_std/no_std_test

cargo +nightly build --release