Use split_first_mut instead of split_at_mut.
This commit is contained in:
parent
c5360db185
commit
6a3e123306
@ -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::<i64>() // 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::<A>().unwrap();
|
||||
let this_ptr: &mut A = &mut *first.write_lock::<A>().unwrap();
|
||||
|
||||
// Immutable reference to the second value parameter
|
||||
// This can be mutable but there is no point because the parameter is passed by value
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user