External Publication
Visit Post

Interior mutability and safety of ownership transfer in Rust

Rust Internals [Unofficial] March 5, 2026
Source

So I just stumbled over the unstable Freeze trait. This seems like a perfect trait bound for the K and V types in order to prevent data races for types with interior mutability (e.g. HashMap<Arc<str>, AtomicUsize>) during buffer migration.

Personally, I think a language level &const T would be even better - or at least more flexible - but for now this seems suitable to me.

That said, the question remains if this idea of mine is sound within the constraints of Rust's ownership model in general. For example, is it safe to have an old Buffer A containing a "non-owning" Vec<T> accessed via shared reference by some threads while simultaneously a new Buffer B containing a bit-wise copy of the same Vec<T> and logical ownership of it is accessed via shared references by other threads.

Discussion in the ATmosphere

Loading comments...