diff --git a/doc/src/rust/register-raw.md b/doc/src/rust/register-raw.md index 5a73cae7..210f419f 100644 --- a/doc/src/rust/register-raw.md +++ b/doc/src/rust/register-raw.md @@ -33,7 +33,7 @@ engine.register_raw_fn( // But remember this is Rust, so you can keep only one mutable reference at any one time! // Therefore, get a '&mut' reference to the first argument _last_. - // Alternatively, use `args.split_at_mut(1)` etc. to split the slice first. + // Alternatively, use `args.split_first_mut()` etc. to split the slice first. let y: i64 = *args[1].read_lock::() // get a reference to the second argument .unwrap(); // then copying it because it is a primary type @@ -163,15 +163,15 @@ Hold Multiple References ------------------------ In order to access a value argument that is expensive to clone _while_ holding a mutable reference -to the first argument, either _consume_ that argument via `mem::take` as above, or use `args.split_at` +to the first argument, either _consume_ that argument via `mem::take` as above, or use `args.split_first` to partition the slice: ```rust // Partition the slice -let (first, rest) = args.split_at_mut(1); +let (first, rest) = args.split_first_mut().unwrap(); // Mutable reference to the first parameter -let this_ptr: &mut A = &mut *first[0].write_lock::().unwrap(); +let this_ptr: &mut A = &mut *first.write_lock::().unwrap(); // Immutable reference to the second value parameter // This can be mutable but there is no point because the parameter is passed by value diff --git a/src/fn_call.rs b/src/fn_call.rs index 7d5e313a..c7300f15 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -521,13 +521,13 @@ impl Engine { let result = if _is_method { // Method call of script function - map first argument to `this` - let (first, rest) = args.split_at_mut(1); + let (first, rest) = args.split_first_mut().unwrap(); self.call_script_fn( scope, mods, state, lib, - &mut Some(first[0]), + &mut Some(*first), fn_name, func, rest,