External Publication
Visit Post

InteriorAssign trait { a := b }

Rust Internals [Unofficial] May 10, 2026
Source

bluelightzero:

For completeness, the current way to do this would be:

num = Some(13)

And another way to do this currently is

num = 13.into();

By the way, a current way to “assign” (rather than “replace”, i.e. not getting back the previous value as an output) inside of a RefCell, that actually uses the assignment operator, would be

*data.ref_cell.borrow_mut() = Some(new_value);

instead of the

data.ref_cell.replace(Some(new_value));

mentioned in the original post of this thread.

Given mem::replace is must_use already, this makes me wonder if RefCell::replace should be must_use, too.

Discussion in the ATmosphere

Loading comments...