Rust Examples

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

ExampleDescription
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.
The serde feature is required to run
simple_fnshows how to register a simple function
stringsshows different ways to register functions taking string arguments

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:

SampleDescriptionOptimizationAllocatorPanics
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

./target/release/no_std_test