How to print both the index and value for every element in a Vec?
问题 I'm trying to complete the activity at the bottom of this page, where I need to print the index of each element as well as the value. I'm starting from the code use std::fmt; // Import the `fmt` module. // Define a structure named `List` containing a `Vec`. struct List(Vec<i32>); impl fmt::Display for List { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // Extract the value using tuple indexing // and create a reference to `vec`. let vec = &self.0; write!(f, "[")?; // Iterate over