this post was submitted on 10 Apr 2024
0 points (NaN% liked)
Rust
5974 readers
15 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
Is it really fair to say retain doesn't compose as well just because it requires reference-based update instead of move-based? I also think using move semantics for in-place updates makes it harder to optimise things like a single field being updated on a large struct.
It also seems harsh to say iterators aren't a zero-cost abstraction if they miss an optimisation that falls outside what the API promises. It's natural to expect
collect
to allocate, no?But I'm only writing this because I wonder if I haven't understood your point fully.
(Side note: I think you could implement the API you want on top of
retain_mut
by usingstd::mem::replace
with a default value, but you'd be hoping that the compiler optimises away all thereplace
calls when it inlines and sees the code can't panic. Idk if that would actually work.)