torophy/util.rs
1pub trait BorrowMutTwo<T> {
2 fn get_two_mut<'a>(&'a mut self, index1: usize, index2: usize) -> (&'a mut T, &'a mut T);
3}
4
5impl<T> BorrowMutTwo<T> for Vec<T> {
6 fn get_two_mut<'a>(&'a mut self, index1: usize, index2: usize) -> (&'a mut T, &'a mut T) {
7 if index1 > index2 {
8 let (a, b) = self.split_at_mut(index1);
9 (&mut b[0], &mut a[index2])
10 }
11 else {
12 let (a, b) = self.split_at_mut(index2);
13 (&mut a[index1], &mut b[0])
14 }
15 }
16}