Alternatively to all of this, if you're just working with a few small array types like `[[T; 4]; 4]`

, you could use a generic approach:

```
fn mutate_2d<V: AsMut<[i32]>>(array: &mut [V]) {
array[1].as_mut()[2] = 1;
}
fn sum_2d<V: AsRef<[i32]>>(array: &[V]) -> i32 {
array.iter()
.map(|v| v.as_ref().iter().sum::<i32>())
.sum()
}
fn main() {
let mut matrix = [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
mutate_2d(&mut matrix);
assert_eq!(sum_2d(&matrix), 5);
}
```

In fact, this function signature even works with vectors. Because it is generic, rust will generate separate, optimized code for each case:

```
let mut vec_of_array = vec![[1, 0, 0], [0, 1, 0], [0, 0, 1]];
let mut array_of_vec = [vec![1, 0, 0], vec![0, 1, 0], vec![0, 0, 1]];
let mut vec_of_vec = vec![vec![1, 0, 0], vec![0, 1, 0], vec![0, 0, 1]];
function_2d(&mut vec_of_array);
function_2d(&mut array_of_vec);
function_2d(&mut vec_of_vec);
```

To make it 3d, you add another type parameter:

```
fn function_3d<V: AsMut<[i32]>, P: AsMut<[V]>>(array: &mut [P]) {
array[1].as_mut()[2].as_mut()[0] = 1;
}
```

is it possible to remove or insert a element from particular position of 2d vector without iterating like in 1d vector

I should note that this is not possible with the `AsMut`

approach, because insertion and removal is only defined for resizable containers like Vec. But based on your original question about array types, I am unsure *why* you would be interested in removing and inserting elements!