You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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};fnget_mut2<'a,A>(mutarr:ArrayViewMut<'a,A,Dim<[Ix;2]>>,[x, y]:[usize;2],[x2, y2]:[usize;2],) -> (&'amutA,&'amutA){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.
Activity
Avoid re-borrowing in multislice! macro
jturner314 commentedon Aug 21, 2019
What do you think of #692?
Avoid re-borrowing in multislice! macro
Avoid re-borrowing in multislice! macro