How to iterate over a two dimensional vector in rust?


This Content is from Stack Overflow. Question asked by Sarang Dutta

I have a mutable reference of vector of mutable references of vectors I want to iterate over the vector and then change the value of its elements.

let mut a = vec![1, 2, 3];
let mut b = vec![4, 5, 6];
let mut c = vec![&mut a , &mut b];
let mut v = &c;

I want to iterate over v and change all of its elements to 0 preferably using an iterator and not by indexing.


Check the Answers

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?