this post was submitted on 10 Apr 2024
32 points (100.0% liked)
Rust
6035 readers
3 users here now
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Wormhole
Credits
- The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
map()
can still be used withVec::iter_mut()
,filter_map()
can be replaced withVec::retain_mut()
.Yeah, that's helpful if I would be currently optimizing a hot loop now. But I was really just using it as an example. Also,
retain_mut()
doesn't compose as well.I'd much rather write:
Over:
And it would be nice if that would be optimized the same. After all, the point of Rust's iterators is to provide zero-cost abstractions. In my opinion, functions like
retain_mut()
represent a leakiness to that abstraction, because the alternative turns out to not be zero cost.https://blog.polybdenum.com/2024/01/17/identifying-the-collect-vec-memory-leak-footgun.html might be relevant to your question.
along with the related https://github.com/rust-lang/rust/issues/120091
Thanks! That’s very much what I was looking for!