Rhai v0.19.15 Release Notes

  • This version replaces all internal usage of HashMap with BTreeMap, which should result in some speed improvement because a BTreeMap is leaner when the number of items held is small. Most, if not all, collections in Rhai hold very few data items, so this is a typical scenario of many tiny-sized collections.

    The Rhai object map type, Map, used to be an alias to HashMap and is now aliased to BTreeMap instead. This is also because, in the vast majority of usage cases, the number of properties held by an object map is small.

    HashMap and BTreeMap have almost identical public API's so this change is unlikely to break existing code.

    SmartString is used to store identifiers (which tend to be short, fewer than 23 characters, and ASCII-based) because they can usually be stored inline. Map keys now also use SmartString.

    ๐Ÿ‘ In addition, there is now support for line continuation in strings (put \ at the end of line) as well as multi-line literal strings (wrapped by back-ticks: `...`).

    ๐Ÿ“‡ Finally, all function signature/metadata methods are now grouped under the umbrella metadata feature. ๐Ÿ“‡ This avoids spending precious resources maintaining metadata for functions for the vast majority of ๐Ÿ‘‰ use cases where such information is not required.

    ๐Ÿ› Bug fixes

    • The feature flags no_index + no_object now compile without errors.

    ๐Ÿ’ฅ Breaking changes

    • The traits RegisterFn and RegisterResultFn are removed. Engine::register_fn and Engine::register_result_fn are now implemented directly on Engine.
    • FnPtr::call_dynamic now takes &NativeCallContext instead of consuming it.
    • All Module::set_fn_XXX methods are removed, in favor of Module::set_native_fn.
    • Array::reduce and Array::reduce_rev now take a Dynamic as initial value instead of a function pointer.
    • protected, super are now reserved keywords.
    • The Module::set_fn_XXX API now take &str as the function name instead of Into<String>.
    • The reflections API such as Engine::gen_fn_signatures, Module::update_fn_metadata etc. are put under the metadata feature gate.
    • The shebang #! is now a reserved symbol.
    • Shebangs at the very beginning of script files are skipped when loading them.
    • ๐Ÿ— SmartString is used for identifiers by default. Currently, a PR branch is pulled for no-std builds. The official crate will be used once SmartString is fixed to support no-std.
    • Map is now an alias to BTreeMap<SmartString, Dynamic> instead of HashMap because most object maps hold few properties.
    • EvalAltResult::FnWrongDefinition is renamed WrongFnDefinition for consistency.

    ๐Ÿ†• New features

    • ๐Ÿ‘ Line continuation (via \) and multi-line literal strings (wrapped with `) support are added.
    • Rhai scripts can now start with a shebang #! which is ignored.

    โœจ Enhancements

    • ๐ŸŽ Replaced all HashMap usage with BTreeMap for better performance because collections in Rhai are tiny.
    • Engine::register_result_fn no longer requires the successful return type to be Dynamic. It can now be any clonable type.
    • #[rhai_fn(return_raw)] can now return Result<T, Box<EvalAltResult>> where T is any clonable type instead of Result<Dynamic, Box<EvalAltResult>>.
    • ๐Ÿ‘ฏ Dynamic::clone_cast is added to simplify casting from a &Dynamic.