Blog Post: Memory Management in Rust and Swift

This is an example code from one answer by matklad:

use std::collections::HashMap;

fn main() {
    let tags_string = "KEY1=VAL1,KEY2=VAL2";
    let tags: HashMap<String, String> = tags_string.split(',')
        .map(|kv| kv.split('=').collect::<Vec<&str>>())
        .map(|vec| {
            assert_eq!(vec.len(), 2);
            (vec[0].to_string(), vec[1].to_string())
        })
        .collect();
}

It contains a .collect::<Vec<_>>(), that's a heap allocation of a 2-items long vector for each input row. I'd like a future Rust compiler to perform Escape Analysis on such code and remove all those heap allocations.