this post was submitted on 10 Apr 2024
32 points (100.0% liked)
Rust
5960 readers
2 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
You're right, I wouldn't say iterators aren't a zero-cost abstraction. But most abstractions are also leaky -- it's just the extent in which the leakiness is exposed that makes them more or less effective. As such, saying to just use
retain_mut
instead of the iterator approach highlights the shortcoming of the abstraction. But if the same results could be achieved while still using the same iterator, that would make that abstraction more useful and consistent. And that's great, because that means we need to worry less when using iterators :)