So I've got a Vec<String>
that's a flattened list of keys and values. I want to iterate over the key/value pairs. I've got this, which works:
let kvlist: Vec<String> = ....;
for i in (0..kvlist.len()).step_by(2) {
println!("key={} value={}", kvlist[i], kvlist[i] + 1);
}
But it seems like it ought to be easy to do this:
for (key, value) in kvlist.some_iterator_magic() {
println!("key={} value={}", key, value);
}
But I don't know what to replace some_iterator_magic
with. I figure I could use skip()
and step_by()
to create iterators on the keys and the values, and then zip()
to create an iterator of pairs over the two, but that doesn't seem like an improvement. Is there something obvious I'm missing? Maybe I can create two slices and zip them?