Description
I'm trying to mutably borrow two elements of an ArrayViewMut
and return them. On 0.12
I've been using split_at
creatively to get multiple mutable references, but it's unwieldy and probably slower than it needs to be.
On master
, multislice!
makes it all a lot more ergonomic and this almost works:
use ndarray::{multislice, Array2, ArrayViewMut, Dim, IndexLonger, Ix, Ix0};
fn get_mut2<'a, A>(
mut arr: ArrayViewMut<'a, A, Dim<[Ix; 2]>>,
[x, y]: [usize; 2],
[x2, y2]: [usize; 2],
) -> (&'a mut A, &'a mut A) {
let (a, b) = multislice!(arr, mut [x, y], mut [x2, y2]);
(a.index(Ix0()), b.index(Ix0()))
}
This fails to compile because it attempts to return the two mutable references which are still bound to the lifetime of the borrow of arr
by multislice!
, and going through IndexLonger
doesn't help.
From what I can tell, this could be fixed if multislice!
was allowed to use the semantics of slice_move()
through some keyword (similarly to how mut
is used to mark mutable slices), or perhaps a multislice_move!
variant that applies move semantics to every returned slice, since it doesn't sound possible to have a both move and non-move semantics in the same multislice
call.
Any thoughts?