Mark pure.

This commit is contained in:
Stephen Chung 2023-01-03 14:00:18 +08:00
parent 9f5783f1a4
commit ae02668d08
2 changed files with 41 additions and 6 deletions

View File

@ -1,6 +1,15 @@
Rhai Release Notes
==================
Version 1.13.0
==============
Bug fixes
---------
* `map` and `filter` for arrays are marked `pure`. Warnings are added to the documentation of pure array methods that take `this` closures.
Version 1.12.0
==============

View File

@ -651,6 +651,8 @@ pub mod array_functions {
///
/// Array element (mutable) is bound to `this`.
///
/// This method is marked _pure_; the `mapper` function should not mutate array elements.
///
/// # Function Parameters
///
/// * `element`: copy of array element
@ -669,7 +671,7 @@ pub mod array_functions {
///
/// print(y); // prints "[0, 2, 6, 12, 20]"
/// ```
#[rhai_fn(return_raw)]
#[rhai_fn(return_raw, pure)]
pub fn map(ctx: NativeCallContext, array: &mut Array, map: FnPtr) -> RhaiResultOf<Array> {
if array.is_empty() {
return Ok(Array::new());
@ -692,6 +694,8 @@ pub mod array_functions {
///
/// Array element (mutable) is bound to `this`.
///
/// This method is marked _pure_; the `filter` function should not mutate array elements.
///
/// # Function Parameters
///
/// * `element`: copy of array element
@ -710,7 +714,7 @@ pub mod array_functions {
///
/// print(y); // prints "[12, 20]"
/// ```
#[rhai_fn(return_raw)]
#[rhai_fn(return_raw, pure)]
pub fn filter(ctx: NativeCallContext, array: &mut Array, filter: FnPtr) -> RhaiResultOf<Array> {
if array.is_empty() {
return Ok(Array::new());
@ -882,6 +886,8 @@ pub mod array_functions {
///
/// Array element (mutable) is bound to `this`.
///
/// This method is marked _pure_; the `filter` function should not mutate array elements.
///
/// # Function Parameters
///
/// * `element`: copy of array element
@ -922,6 +928,8 @@ pub mod array_functions {
///
/// Array element (mutable) is bound to `this`.
///
/// This method is marked _pure_; the `filter` function should not mutate array elements.
///
/// # Function Parameters
///
/// * `element`: copy of array element
@ -1011,6 +1019,8 @@ pub mod array_functions {
///
/// Array element (mutable) is bound to `this`.
///
/// This method is marked _pure_; the `filter` function should not mutate array elements.
///
/// # Function Parameters
///
/// * `element`: copy of array element
@ -1055,6 +1065,8 @@ pub mod array_functions {
///
/// Array element (mutable) is bound to `this`.
///
/// This method is marked _pure_; the `mapper` function should not mutate array elements.
///
/// # Function Parameters
///
/// * `element`: copy of array element
@ -1087,6 +1099,8 @@ pub mod array_functions {
///
/// Array element (mutable) is bound to `this`.
///
/// This method is marked _pure_; the `mapper` function should not mutate array elements.
///
/// # Function Parameters
///
/// * `element`: copy of array element
@ -1143,6 +1157,8 @@ pub mod array_functions {
///
/// Array element (mutable) is bound to `this`.
///
/// This method is marked _pure_; the `filter` function should not mutate array elements.
///
/// # Function Parameters
///
/// * `element`: copy of array element
@ -1185,6 +1201,8 @@ pub mod array_functions {
///
/// Array element (mutable) is bound to `this`.
///
/// This method is marked _pure_; the `filter` function should not mutate array elements.
///
/// # Function Parameters
///
/// * `element`: copy of array element
@ -1281,9 +1299,11 @@ pub mod array_functions {
/// # Function Parameters
///
/// * `result`: accumulated result, initially `()`
/// * `element`: copy of array element
/// * `element`: copy of array element, or bound to `this` if omitted
/// * `index` _(optional)_: current index in the array
///
/// This method is marked _pure_; the `reducer` function should not mutate array elements.
///
/// # Example
///
/// ```rhai
@ -1306,9 +1326,11 @@ pub mod array_functions {
/// # Function Parameters
///
/// * `result`: accumulated result, starting with the value of `initial`
/// * `element`: copy of array element
/// * `element`: copy of array element, or bound to `this` if omitted
/// * `index` _(optional)_: current index in the array
///
/// This method is marked _pure_; the `reducer` function should not mutate array elements.
///
/// # Example
///
/// ```rhai
@ -1347,9 +1369,11 @@ pub mod array_functions {
/// # Function Parameters
///
/// * `result`: accumulated result, initially `()`
/// * `element`: copy of array element
/// * `element`: copy of array element, or bound to `this` if omitted
/// * `index` _(optional)_: current index in the array
///
/// This method is marked _pure_; the `reducer` function should not mutate array elements.
///
/// # Example
///
/// ```rhai
@ -1373,9 +1397,11 @@ pub mod array_functions {
/// # Function Parameters
///
/// * `result`: accumulated result, starting with the value of `initial`
/// * `element`: copy of array element
/// * `element`: copy of array element, or bound to `this` if omitted
/// * `index` _(optional)_: current index in the array
///
/// This method is marked _pure_; the `reducer` function should not mutate array elements.
///
/// # Example
///
/// ```rhai