The best way to modify vector

I want to modify an vector, if i gonna modify an array in javascript i would probably do something like this

let mut array = vec!["hello", "there"];

array[1] = "world";

Is this the best way to modify an array in rust?

Yes, the a[i] = value; syntax is how slices, vectors, and arrays are modified. These collections all implement the IndexMut trait, which allows them to be modified at an index, as you have done.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.