fn set_index<C, T>(v: &mut C, index: usize, value: T)Expand description
Sets the value at a given index in a collection.
If the index is out of bounds, the collection is automatically extended
with default values (T::default()) up to the required index.
§Behavior
- If
index < current length, the value is simply updated. - If
index >= current length, the collection is resized by filling missing positions with default values, then the value is set.
§Type Parameters
C: A collection that supports indexing and extension.T: The element type, which must implementDefault.
§Example
If the collection has length 3 and you set index 5:
- Elements at index 3 and 4 will be filled with
T::default(). - Index 5 will be assigned the given
value.