I definitely agree that std::mem::replace
is one of Rust's best-kept secrets, and that it should be more discoverable. I'm not sure how much the prelude would help with that goal, but it might.
As an aside: If I were designing a Rust-like language from scratch today, instead of an assignment operator I would include an infix operator like a <- b
that is equivalent to replace(&mut a, b)
, and perhaps a <-> b
to mean swap(&mut a, &mut b)
.