Rhai v1.9.0 Release Notes

  • The minimum Rust version is now 1.60.0 in order to use the dep: syntax for dependencies.

    ๐Ÿ› Bug fixes

    • โšก๏ธ switch cases with conditions that evaluate to constant () no longer optimize to false (should raise a type error during runtime).
    • ๐Ÿ›  Fixes concatenation of BLOB's and strings, where the BLOB's should be interpreted as UTF-8 encoded strings.
    • Capturing an unknown variable in a closure no longer panics.
    • ๐Ÿ›  Fixes panic in interpolated strings with constant expressions.
    • Using call_fn_raw on a function without evaluating the AST no longer panics on namespace-qualified function calls due to import statements not run.
    • ๐Ÿ›  Some reserved tokens (such as "?", "++") cannot be used in custom syntax; this is now fixed.

    ๐Ÿ’ฅ Breaking changes

    • The first closure passed to Engine::register_debugger now takes a single parameter which is a reference to the current Engine.

    ๐Ÿ†• New features

    ๐Ÿ†• New feature flags

    • 0๏ธโƒฃ A new feature flag, std, which is enabled by default, is added due to requirements from dependency crates.
    • A new feature flag, no_custom_syntax, is added to remove custom syntax support from Rhai for applications that do not require it (which should be most).

    ๐Ÿ“š Module documentation

    • ๐Ÿ“š Comment lines beginning with //! (requires the metadata feature) are now collected as the script file's module documentation.
    • ๐Ÿ“š AST and Module have methods to access and manipulate documentation.

    Output definition files

    • ๐Ÿ”ง An API is added to automatically generate definition files from a fully-configured Engine, for use with the Rhai Language Server.

    Short-hand to function pointers

    • Using a script-defined function's name (in place of a variable) implicitly creates a function pointer to the function.

    Top-level functions

    • Crate-level functions rhai::eval, rhai::run, rhai::eval_file, rhai::run_file are added as convenient wrappers.

    CustomType trait and TypeBuilder

    • ๐Ÿ— A new volatile API, Engine::build_type, enables registration of the entire API of a custom type in one go, provided that the custom type implements the CustomType trait (which uses TypeBuilder to register the API functions).

    ๐Ÿ“ฆ Simpler Package API

    • It is now easier to register packages via the Package::register_into_engine and Package::register_into_engine_as API.
    • ๐Ÿ“ฆ Defining a custom package with base packages is also much easier with a new syntax - put the new base packages after a colon.

    โœจ Enhancements

    switch statement

    • switch cases can now include multiple values separated by |.
    • Duplicated switch cases are now allowed.
    • ๐Ÿ‘€ The error ParseErrorType::DuplicatedSwitchCase is deprecated.
    • Ranges in switch statements that are small (currently no more than 16 items) are unrolled if possible.

    Others

    • EvalContext::eval_expression_tree_raw and Expression::eval_with_context_raw are added to allow for not rewinding the Scope at the end of a statements block.
    • A new range function variant that takes an exclusive range with a step.
    • as_string is added to BLOB's to convert it into a string by interpreting it as a UTF-8 byte stream.
    • FnAccess::is_private, FnAccess::is_public, FnNamespace::is_module_namespace and FnNameSpace::is_global_namespace are added for convenience.
    • ๐Ÿ“‡ Iterator<Item=T> type for functions metadata is simplified to Iterator<T>.
    • ๐Ÿšš Scope::remove is added to remove a variable from a Scope, returning its value.
    • The code base is cleaner by running it through Clippy.
    • ๐Ÿ‘€ ParseError::err_type and ParseError::position are added for convenience.
    • The source of an AST compiled from a script file is set to the file's path.
    • |> and <| are now reserved symbols.