Get the latest tech news
Understanding Memory Management, Part 5: Fighting with Rust
by ekr on 20 Apr 2025 This is the fifth post in my planned multipart series on memory management. You will probably want to go back and read Part I, which covers C, parts II and III, which cover C++, and part IV, which introduces Rust memory management.
When we do IntoIterator::to_iter(x) this tells Rust to expect a version of to_iter() that takes a value argument (i.e., Vec<i32>) which means we have to move x into the function, so we can't reuse it. This was obviously a pain in the ass and Rust eventually added a feature called non-lexical lifetimes which made the compiler smarter about knowing when references were really live. This great post by Dmitry Vyukov) goes into a lot more detail here, but the basic point is that if you ever do uncoordinated writes to the same data values it's incredibly bad news (again, it's undefined behavior in C/C++).
Or read this on Hacker News