From b8b1efd2413bc23cf20372543ea3881a4b399fb6 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 6 Aug 2020 21:11:24 +0800 Subject: [PATCH] Add note on `&T` parameters. --- doc/src/language/method.md | 6 ++++-- doc/src/rust/custom.md | 6 ++++-- doc/src/rust/getters-setters.md | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/src/language/method.md b/doc/src/language/method.md index 290d1a06..3b8a82d4 100644 --- a/doc/src/language/method.md +++ b/doc/src/language/method.md @@ -36,6 +36,8 @@ update(array[0]); // <- 'array[0]' is an expression returning a calculated val array[0].update(); // <- call in method-call style will update 'a' ``` +**IMPORTANT: Rhai does NOT support normal references (i.e. `&T`) as parameters.** + Number of Parameters -------------------- @@ -51,8 +53,8 @@ The following table illustrates the differences: | Rhai script | _n_ | `this` | `fn method(x, y) {}` | -`&mut` is Efficient (Except for `ImmutableString`) ------------------------------------------------- +`&mut` is Efficient, Except for `ImmutableString` +----------------------------------------------- Using a `&mut` first parameter is highly encouraged when using types that are expensive to clone, even when the intention is not to mutate that argument, because it avoids cloning that argument value. diff --git a/doc/src/rust/custom.md b/doc/src/rust/custom.md index 3e6b5ca3..b2325204 100644 --- a/doc/src/rust/custom.md +++ b/doc/src/rust/custom.md @@ -83,6 +83,8 @@ engine ***Note**: Rhai follows the convention that methods of custom types take a `&mut` first parameter so that invoking methods can update the types. All other parameters in Rhai are passed by value (i.e. clones).* +**IMPORTANT: Rhai does NOT support normal references (i.e. `&T`) as parameters.** + Use the Custom Type in Scripts ----------------------------- @@ -125,8 +127,8 @@ Under [`no_object`], however, the _method_ style of function calls let result = engine.eval::<()>("let x = [1, 2, 3]; x.clear()")?; ``` -[`type_of()`] -------------- +`type_of()` a Custom Type +------------------------- [`type_of()`] works fine with custom types and returns the name of the type. diff --git a/doc/src/rust/getters-setters.md b/doc/src/rust/getters-setters.md index 4c44399d..7597e8d5 100644 --- a/doc/src/rust/getters-setters.md +++ b/doc/src/rust/getters-setters.md @@ -42,3 +42,5 @@ let result = engine.eval::(r#"let a = new_ts(); a.xyz = "42"; a.xyz"#)?; println!("Answer: {}", result); // prints 42 ``` + +**IMPORTANT: Rhai does NOT support normal references (i.e. `&T`) as parameters.**